From f9caad95b9f31b8dbd268ff5e167f0ddeaac73c2 Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 17 Jun 2025 17:22:39 +0800 Subject: [PATCH] fix: [AddField] Check field empty instead of existence (#42789) Related to #42773 Growing segment fills all known meta into `InsertRecord` data, which cause even the field is missing, the field data will still exists. This PR update the logic while finish loading growing segment to check field empty or not instead of existence. --------- Signed-off-by: Congqi Xia --- internal/core/src/segcore/SegmentGrowingImpl.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/core/src/segcore/SegmentGrowingImpl.cpp b/internal/core/src/segcore/SegmentGrowingImpl.cpp index a482eb3de2..1e18eb961c 100644 --- a/internal/core/src/segcore/SegmentGrowingImpl.cpp +++ b/internal/core/src/segcore/SegmentGrowingImpl.cpp @@ -1253,7 +1253,9 @@ SegmentGrowingImpl::FinishLoad() { if (field_id.get() < START_USER_FIELDID) { continue; } - if (!insert_record_.is_data_exist(field_id)) { + // append_data is called according to schema before + // so we must check data empty here + if (!IsVectorDataType(field_meta.get_data_type()) &&insert_record_.get_data_base(field_id)->empty()) { fill_empty_field(field_meta); } } @@ -1262,7 +1264,12 @@ SegmentGrowingImpl::FinishLoad() { void SegmentGrowingImpl::fill_empty_field(const FieldMeta& field_meta) { auto field_id = field_meta.get_id(); - insert_record_.append_field_meta(field_id, field_meta, size_per_chunk()); + // append meta only needed when schema is old + // loading old segment with new schema will have meta appended + if (!insert_record_.is_data_exist(field_id)) { + insert_record_.append_field_meta( + field_id, field_meta, size_per_chunk()); + } auto total_row_num = insert_record_.size(); @@ -1271,6 +1278,9 @@ SegmentGrowingImpl::fill_empty_field(const FieldMeta& field_meta) { 0, total_row_num, data.get(), field_meta); insert_record_.get_valid_data(field_id)->set_data_raw( total_row_num, data.get(), field_meta); + LOG_INFO("Growing segment {} fill empty field {} done", + this->get_segment_id(), + field_meta.get_id().get()); } } // namespace milvus::segcore