From 084140b0937d97be01ce6d8c55273f2390c1ed9b Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 6 Jun 2024 11:45:51 +0800 Subject: [PATCH] enhance: [2.4] Make hasMoreResult accurate when hit number larger than limit(#33609) (#33642) Cherry-pick from master pr: #33609 See also milvus-io/milvus-sdk-go#756 Signed-off-by: Congqi Xia --- internal/core/src/segcore/InsertRecord.h | 3 ++- internal/core/unittest/test_offset_ordered_array.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/core/src/segcore/InsertRecord.h b/internal/core/src/segcore/InsertRecord.h index 13a92d22e760a..e4b208bfc24b4 100644 --- a/internal/core/src/segcore/InsertRecord.h +++ b/internal/core/src/segcore/InsertRecord.h @@ -259,6 +259,7 @@ class OffsetOrderedArray : public OffsetMap { if (!false_filtered_out) { cnt = size - bitset.count(); } + auto more_hit_than_limit = cnt > limit; limit = std::min(limit, cnt); std::vector seg_offsets; seg_offsets.reserve(limit); @@ -275,7 +276,7 @@ class OffsetOrderedArray : public OffsetMap { hit_num++; } } - return {seg_offsets, it != array_.end()}; + return {seg_offsets, more_hit_than_limit && it != array_.end()}; } void diff --git a/internal/core/unittest/test_offset_ordered_array.cpp b/internal/core/unittest/test_offset_ordered_array.cpp index 1eb2e272b0f8f..fd817fbdd5b92 100644 --- a/internal/core/unittest/test_offset_ordered_array.cpp +++ b/internal/core/unittest/test_offset_ordered_array.cpp @@ -130,10 +130,10 @@ TYPED_TEST_P(TypedOffsetOrderedArrayTest, find_first) { none.reset(); auto result_pair = this->map_.find_first(num / 2, none, true); ASSERT_EQ(0, result_pair.first.size()); - ASSERT_TRUE(result_pair.second); + ASSERT_FALSE(result_pair.second); result_pair = this->map_.find_first(NoLimit, none, true); ASSERT_EQ(0, result_pair.first.size()); - ASSERT_TRUE(result_pair.second); + ASSERT_FALSE(result_pair.second); } }