Optimize the performance of matching prefix for string index (#22712)

Signed-off-by: yah01 <yang.cen@zilliz.com>
pull/22730/head
yah01 2023-03-13 17:31:53 +08:00 committed by GitHub
parent f314d887f8
commit 8f3d6e08df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -17,6 +17,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <string> #include <string>
#include <string_view>
#include "common/Utils.h" #include "common/Utils.h"
#include "index/ScalarIndexSort.h" #include "index/ScalarIndexSort.h"
@ -40,10 +41,17 @@ class StringIndexSort : public ScalarIndexSort<std::string> {
PrefixMatch(std::string_view prefix) { PrefixMatch(std::string_view prefix) {
auto data = GetData(); auto data = GetData();
TargetBitmapPtr bitset = std::make_unique<TargetBitmap>(data.size()); TargetBitmapPtr bitset = std::make_unique<TargetBitmap>(data.size());
for (size_t i = 0; i < data.size(); i++) { auto it = std::lower_bound(
if (milvus::PrefixMatch(data[i].a_, prefix)) { data.begin(),
bitset->set(data[i].idx_); data.end(),
prefix,
[](const IndexStructure<std::string>& value,
std::string_view prefix) { return value.a_ < prefix; });
for (; it != data.end(); ++it) {
if (!milvus::PrefixMatch(it->a_, prefix)) {
break;
} }
bitset->set(it->idx_);
} }
return bitset; return bitset;
} }