Skip to content

Commit

Permalink
support skip-index based on chunk-metrics to accelerate expr filter(#…
Browse files Browse the repository at this point in the history
…27925)

Signed-off-by: MrPresent-Han <[email protected]>
  • Loading branch information
MrPresent-Han committed Nov 14, 2023
1 parent f8aa464 commit f0e3aff
Show file tree
Hide file tree
Showing 13 changed files with 909 additions and 81 deletions.
50 changes: 50 additions & 0 deletions internal/core/src/index/ScalarIndexSort-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ ScalarIndexSort<T>::Range(const T value, const OpType op) {
TargetBitmap bitset(data_.size());
auto lb = data_.begin();
auto ub = data_.end();
if (ShouldSkip(value, value, op)) {
return bitset;

Check warning on line 240 in internal/core/src/index/ScalarIndexSort-inl.h

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/ScalarIndexSort-inl.h#L240

Added line #L240 was not covered by tests
}
switch (op) {
case OpType::LessThan:
ub = std::lower_bound(
Expand Down Expand Up @@ -276,6 +279,9 @@ ScalarIndexSort<T>::Range(T lower_bound_value,
!(lb_inclusive && ub_inclusive))) {
return bitset;
}
if (ShouldSkip(lower_bound_value, upper_bound_value, OpType::Range)) {
return bitset;

Check warning on line 283 in internal/core/src/index/ScalarIndexSort-inl.h

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/ScalarIndexSort-inl.h#L283

Added line #L283 was not covered by tests
}
auto lb = data_.begin();
auto ub = data_.end();
if (lb_inclusive) {
Expand Down Expand Up @@ -307,4 +313,48 @@ ScalarIndexSort<T>::Reverse_Lookup(size_t idx) const {
auto offset = idx_to_offsets_[idx];
return data_[offset].a_;
}

template <typename T>
inline bool
ScalarIndexSort<T>::ShouldSkip(const T lower_value,
const T upper_value,
const milvus::OpType op) {
if (!data_.empty()) {
auto lower_bound = data_.begin();
auto upper_bound = data_.rbegin();
bool shouldSkip = false;
switch (op) {
case OpType::LessThan: {
shouldSkip = upper_value <= lower_bound->a_;
break;
}
case OpType::LessEqual: {
shouldSkip = upper_value < lower_bound->a_;
break;
}
case OpType::GreaterThan: {
shouldSkip = lower_value >= upper_bound->a_;
break;
}
case OpType::GreaterEqual: {
shouldSkip = lower_value > upper_bound->a_;
break;
}
case OpType::Range: {
shouldSkip = (lower_value > upper_bound->a_) ||
(upper_value < lower_bound->a_);
break;
}
default:

Check warning on line 348 in internal/core/src/index/ScalarIndexSort-inl.h

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/ScalarIndexSort-inl.h#L348

Added line #L348 was not covered by tests
throw SegcoreError(
OpTypeInvalid,
fmt::format("Invalid OperatorType for "
"checking scalar index optimization: {}",
op));

Check warning on line 353 in internal/core/src/index/ScalarIndexSort-inl.h

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/ScalarIndexSort-inl.h#L353

Added line #L353 was not covered by tests
}
return shouldSkip;
}
return true;

Check warning on line 357 in internal/core/src/index/ScalarIndexSort-inl.h

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/ScalarIndexSort-inl.h#L357

Added line #L357 was not covered by tests
}

} // namespace milvus::index
4 changes: 4 additions & 0 deletions internal/core/src/index/ScalarIndexSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class ScalarIndexSort : public ScalarIndex<T> {
BinarySet
Upload(const Config& config = {}) override;

private:
bool
ShouldSkip(const T lower_value, const T upper_value, const OpType op);

public:
const std::vector<IndexStructure<T>>&
GetData() {
Expand Down
8 changes: 6 additions & 2 deletions internal/core/src/query/generated/ExecExprVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ class ExecExprVisitor : public ExprVisitor {
}

public:
template <typename T, typename IndexFunc, typename ElementFunc>
template <typename T,
typename IndexFunc,
typename ElementFunc,
typename SkipIndexFunc>
auto
ExecRangeVisitorImpl(FieldId field_id,
IndexFunc func,
ElementFunc element_func) -> BitsetType;
ElementFunc element_func,
SkipIndexFunc skip_index_func) -> BitsetType;

template <typename T, typename IndexFunc, typename ElementFunc>
auto
Expand Down
Loading

0 comments on commit f0e3aff

Please sign in to comment.