Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions internal/core/src/exec/expression/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1189,22 +1189,17 @@ 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++) {
auto pw =
segment_->chunk_scalar_index<IndexInnerType>(field_id_, i);
auto index_ptr = const_cast<Index*>(pw.get());
// 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_ptr->SupportRegexQuery() &&
!index_ptr->HasRawData()) {
return false;
}
// all chunks have same index.
return true;
}
if (op == OpType::Match || op == OpType::InnerMatch ||
op == OpType::PostfixMatch) {
auto pw = segment_->chunk_scalar_index<IndexInnerType>(
field_id_, current_index_chunk_);
auto* index_ptr = const_cast<Index*>(pw.get());
// 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_ptr->TryUseRegexQuery() &&
index_ptr->SupportRegexQuery()) ||
index_ptr->HasRawData();
}

return true;
}

Expand Down
17 changes: 13 additions & 4 deletions internal/core/src/exec/expression/UnaryExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,17 +1828,26 @@
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 &&

Check warning on line 1845 in internal/core/src/exec/expression/UnaryExpr.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/exec/expression/UnaryExpr.cpp#L1842-L1845

Added lines #L1842 - L1845 were not covered by tests
expr_->op_type_ != proto::plan::OpType::InnerMatch;
break;

Check warning on line 1847 in internal/core/src/exec/expression/UnaryExpr.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/exec/expression/UnaryExpr.cpp#L1847

Added line #L1847 was not covered by tests
default:
use_index_ = has_index;
}
return use_index_;
}

Expand Down
5 changes: 5 additions & 0 deletions internal/core/src/index/HybridScalarIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
return internal_index_->PatternMatch(pattern, op);
}

bool
TryUseRegexQuery() const override {
return internal_index_->TryUseRegexQuery();

Check warning on line 120 in internal/core/src/index/HybridScalarIndex.h

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/HybridScalarIndex.h#L119-L120

Added lines #L119 - L120 were not covered by tests
}

bool
SupportRegexQuery() const override {
return internal_index_->SupportRegexQuery();
Expand Down
6 changes: 6 additions & 0 deletions internal/core/src/index/InvertedIndexTantivy.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,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;

Expand Down
5 changes: 5 additions & 0 deletions internal/core/src/index/ScalarIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading