enhance: use scan mode for like although inverted index exists (#41309)

#41065

Signed-off-by: luzhang <luzhang@zilliz.com>
Co-authored-by: luzhang <luzhang@zilliz.com>
pull/41329/head
zhagnlu 2025-04-15 18:36:32 +08:00 committed by GitHub
parent 3e06b2c9e7
commit 2aae9caca9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 17 deletions

View File

@ -1183,20 +1183,15 @@ class SegmentExpr : public Expr {
}
using Index = index::ScalarIndex<IndexInnerType>;
if (op == OpType::Match) {
for (size_t i = current_index_chunk_; i < num_index_chunk_; i++) {
const Index& index =
segment_->chunk_scalar_index<IndexInnerType>(field_id_, i);
// 1, index support regex query, then index handles the query;
// 2, index has raw data, then call index.Reverse_Lookup to handle the query;
if (!index.SupportRegexQuery() && !index.HasRawData()) {
return false;
}
// all chunks have same index.
return true;
}
if (op == OpType::Match || op == OpType::InnerMatch ||
op == OpType::PostfixMatch) {
const Index& index = segment_->chunk_scalar_index<IndexInnerType>(
field_id_, current_index_chunk_);
// 1, index support regex query and try use it, then index handles the query;
// 2, index has raw data, then call index.Reverse_Lookup to handle the query;
return (index.TryUseRegexQuery() && index.SupportRegexQuery()) ||
index.HasRawData();
}
return true;
}

View File

@ -1860,17 +1860,26 @@ PhyUnaryRangeFilterExpr::ExecRangeVisitorImplForData(EvalCtx& context) {
template <typename T>
bool
PhyUnaryRangeFilterExpr::CanUseIndex() {
bool res = is_index_mode_ && SegmentExpr::CanUseIndex<T>(expr_->op_type_);
use_index_ = res;
return res;
use_index_ = is_index_mode_ && SegmentExpr::CanUseIndex<T>(expr_->op_type_);
return use_index_;
}
bool
PhyUnaryRangeFilterExpr::CanUseIndexForJson(DataType val_type) {
use_index_ =
auto has_index =
segment_->HasIndex(field_id_,
milvus::Json::pointer(expr_->column_.nested_path_),
val_type);
switch (val_type) {
case DataType::STRING:
use_index_ = has_index &&
expr_->op_type_ != proto::plan::OpType::Match &&
expr_->op_type_ != proto::plan::OpType::PostfixMatch &&
expr_->op_type_ != proto::plan::OpType::InnerMatch;
break;
default:
use_index_ = has_index;
}
return use_index_;
}

View File

@ -226,6 +226,12 @@ class InvertedIndexTantivy : public ScalarIndex<T> {
return std::is_same_v<T, std::string>;
}
bool
TryUseRegexQuery() const override {
// for inverted index, not use regex query to implement match
return false;
}
const TargetBitmap
RegexQuery(const std::string& regex_pattern) override;

View File

@ -151,6 +151,11 @@ class ScalarIndex : public IndexBase {
return false;
}
virtual bool
TryUseRegexQuery() const {
return true;
}
virtual const TargetBitmap
RegexQuery(const std::string& pattern) {
PanicInfo(Unsupported, "regex query is not supported");