Skip to content

Commit

Permalink
Use PK index for string data type (#25402)
Browse files Browse the repository at this point in the history
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
  • Loading branch information
bigsheeper committed Jul 12, 2023
1 parent f95e05f commit 96ba92d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
17 changes: 3 additions & 14 deletions internal/core/src/query/visitors/ExecExprVisitor.cpp
Expand Up @@ -1363,7 +1363,8 @@ ExecExprVisitor::visit(CompareExpr& expr) {
template <typename T>
auto
ExecExprVisitor::ExecTermVisitorImpl(TermExpr& expr_raw) -> BitsetType {
auto& expr = static_cast<TermExprImpl<T>&>(expr_raw);
typedef std::conditional_t<std::is_same_v<T, std::string_view>, std::string, T> InnerType;
auto& expr = static_cast<TermExprImpl<InnerType>&>(expr_raw);
auto& schema = segment_.get_schema();
auto primary_filed_id = schema.get_primary_field_id();
auto field_id = expr_raw.column_.field_id;
Expand Down Expand Up @@ -1409,25 +1410,13 @@ ExecExprVisitor::ExecTermVisitorImpl(TermExpr& expr_raw) -> BitsetType {
return ExecTermVisitorImplTemplate<T>(expr_raw);
}

template <>
auto
ExecExprVisitor::ExecTermVisitorImpl<std::string>(TermExpr& expr_raw) -> BitsetType {
return ExecTermVisitorImplTemplate<std::string>(expr_raw);
}

template <>
auto
ExecExprVisitor::ExecTermVisitorImpl<std::string_view>(TermExpr& expr_raw) -> BitsetType {
return ExecTermVisitorImplTemplate<std::string_view>(expr_raw);
}

template <typename T>
auto
ExecExprVisitor::ExecTermVisitorImplTemplate(TermExpr& expr_raw) -> BitsetType {
typedef std::conditional_t<std::is_same_v<T, std::string_view>, std::string, T> IndexInnerType;
using Index = index::ScalarIndex<IndexInnerType>;
auto& expr = static_cast<TermExprImpl<IndexInnerType>&>(expr_raw);
const std::vector<IndexInnerType> terms(expr.terms_.begin(), expr.terms_.end());
const auto& terms = expr.terms_;
auto n = terms.size();
std::unordered_set<T> term_set(expr.terms_.begin(), expr.terms_.end());

Expand Down
1 change: 0 additions & 1 deletion internal/core/src/segcore/SegmentGrowingImpl.cpp
Expand Up @@ -394,7 +394,6 @@ SegmentGrowingImpl::search_ids(const BitsetView& bitset, Timestamp timestamp) co

std::pair<std::unique_ptr<IdArray>, std::vector<SegOffset>>
SegmentGrowingImpl::search_ids(const IdArray& id_array, Timestamp timestamp) const {
AssertInfo(id_array.has_int_id(), "Id array doesn't have int_id element");
auto field_id = schema_->get_primary_field_id().value_or(FieldId(-1));
AssertInfo(field_id.get() != -1, "Primary key is -1");
auto& field_meta = schema_->operator[](field_id);
Expand Down
1 change: 0 additions & 1 deletion internal/core/src/segcore/SegmentSealedImpl.cpp
Expand Up @@ -679,7 +679,6 @@ SegmentSealedImpl::HasRawData(int64_t field_id) const {

std::pair<std::unique_ptr<IdArray>, std::vector<SegOffset>>
SegmentSealedImpl::search_ids(const IdArray& id_array, Timestamp timestamp) const {
AssertInfo(id_array.has_int_id(), "Id array doesn't have int_id element");
auto field_id = schema_->get_primary_field_id().value_or(FieldId(-1));
AssertInfo(field_id.get() != -1, "Primary key is -1");
auto& field_meta = schema_->operator[](field_id);
Expand Down

0 comments on commit 96ba92d

Please sign in to comment.