diff --git a/internal/core/src/segcore/SegmentGrowingImpl.cpp b/internal/core/src/segcore/SegmentGrowingImpl.cpp index e36692de02..5e1cadb3df 100644 --- a/internal/core/src/segcore/SegmentGrowingImpl.cpp +++ b/internal/core/src/segcore/SegmentGrowingImpl.cpp @@ -353,8 +353,38 @@ SegmentGrowingImpl::LoadDeletedRecord(const LoadDeletedRecordInfo& info) { ParsePksFromIDs(pks, field_meta.get_data_type(), *info.primary_keys); auto timestamps = reinterpret_cast(info.timestamps); - // step 2: fill pks and timestamps - deleted_record_.push(pks, timestamps); + std::vector> ordering(size); + for (int i = 0; i < size; i++) { + ordering[i] = std::make_tuple(timestamps[i], pks[i]); + } + + if (!insert_record_.empty_pks()) { + auto end = std::remove_if( + ordering.begin(), + ordering.end(), + [&](const std::tuple& record) { + return !insert_record_.contain(std::get<1>(record)); + }); + size = end - ordering.begin(); + ordering.resize(size); + } + + // all record filtered + if (size == 0) { + return; + } + + std::sort(ordering.begin(), ordering.end()); + std::vector sort_pks(size); + std::vector sort_timestamps(size); + + for (int i = 0; i < size; i++) { + auto [t, pk] = ordering[i]; + sort_timestamps[i] = t; + sort_pks[i] = pk; + } + + deleted_record_.push(sort_pks, sort_timestamps.data()); } SpanBase diff --git a/internal/core/src/segcore/SegmentSealedImpl.cpp b/internal/core/src/segcore/SegmentSealedImpl.cpp index 94bffbbae7..2d5424b961 100644 --- a/internal/core/src/segcore/SegmentSealedImpl.cpp +++ b/internal/core/src/segcore/SegmentSealedImpl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -606,8 +607,38 @@ SegmentSealedImpl::LoadDeletedRecord(const LoadDeletedRecordInfo& info) { ParsePksFromIDs(pks, field_meta.get_data_type(), *info.primary_keys); auto timestamps = reinterpret_cast(info.timestamps); - // step 2: fill pks and timestamps - deleted_record_.push(pks, timestamps); + std::vector> ordering(size); + for (int i = 0; i < size; i++) { + ordering[i] = std::make_tuple(timestamps[i], pks[i]); + } + + if (!insert_record_.empty_pks()) { + auto end = std::remove_if( + ordering.begin(), + ordering.end(), + [&](const std::tuple& record) { + return !insert_record_.contain(std::get<1>(record)); + }); + size = end - ordering.begin(); + ordering.resize(size); + } + + // all record filtered + if (size == 0) { + return; + } + + std::sort(ordering.begin(), ordering.end()); + std::vector sort_pks(size); + std::vector sort_timestamps(size); + + for (int i = 0; i < size; i++) { + auto [t, pk] = ordering[i]; + sort_timestamps[i] = t; + sort_pks[i] = pk; + } + + deleted_record_.push(sort_pks, sort_timestamps.data()); } void