enhance: optimize the performance of binary_search_string (#44470)

pr: #44469

Signed-off-by: sunby <sunbingyi1992@gmail.com>
This commit is contained in:
Bingyi Sun 2025-09-23 14:28:05 +08:00 committed by GitHub
parent 8b0bfe4cd8
commit c5a7845531
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -113,7 +113,7 @@ class FixedWidthChunk : public Chunk {
std::unique_ptr<MmapFileRAII> mmap_file_raii = nullptr) std::unique_ptr<MmapFileRAII> mmap_file_raii = nullptr)
: Chunk(row_nums, data, size, nullable, std::move(mmap_file_raii)), : Chunk(row_nums, data, size, nullable, std::move(mmap_file_raii)),
dim_(dim), dim_(dim),
element_size_(element_size){}; element_size_(element_size) {};
milvus::SpanBase milvus::SpanBase
Span() const { Span() const {
@ -180,10 +180,12 @@ class StringChunk : public Chunk {
while (left <= right) { while (left <= right) {
int mid = left + (right - left) / 2; int mid = left + (right - left) / 2;
std::string_view midString = (*this)[mid]; std::string_view midString = (*this)[mid];
if (midString == target) { auto cmp = midString.compare(target);
if (cmp == 0) {
result = mid; // Store the index of match result = mid; // Store the index of match
right = mid - 1; // Continue searching in the left half right = mid - 1; // Continue searching in the left half
} else if (midString < target) { } else if (cmp < 0) {
// midString < target // midString < target
left = mid + 1; left = mid + 1;
} else { } else {