diff --git a/be/src/olap/comparison_predicate.h b/be/src/olap/comparison_predicate.h index fbeb36ed9603917..ba3e0d88719a8cf 100644 --- a/be/src/olap/comparison_predicate.h +++ b/be/src/olap/comparison_predicate.h @@ -213,7 +213,7 @@ class ComparisonPredicateBase : public ColumnPredicate { const Schema& schema) const override { if (query_value == nullptr) { auto column_desc = schema.column(_column_id); - if constexpr (PT == PredicateType::EQ) { + if constexpr (PT == PredicateType::EQ || PT == PredicateType::NE) { query_value = std::make_unique>( column_desc->type_info()); } else { @@ -221,7 +221,7 @@ class ComparisonPredicateBase : public ColumnPredicate { column_desc->type_info()); } } - if constexpr (PT == PredicateType::EQ) { + if constexpr (PT == PredicateType::EQ || PT == PredicateType::NE) { auto q = static_cast*>(query_value.get()); q->add_value(&_value, InvertedIndexQueryType::EQUAL_QUERY); } else { diff --git a/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.cpp b/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.cpp index 4787e3e84d14658..fd65dbb543d93e8 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.cpp +++ b/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.cpp @@ -170,12 +170,14 @@ template Status InvertedIndexRangeQuery::add_value(const T& value, InvertedIndexQueryType t) { switch (t) { case InvertedIndexQueryType::GREATER_THAN_QUERY: { + _low_value = &value; _low_value_encoded.clear(); _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); break; } case InvertedIndexQueryType::GREATER_EQUAL_QUERY: { + _low_value = &value; _inclusive_low = true; _low_value_encoded.clear(); _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); @@ -183,18 +185,21 @@ Status InvertedIndexRangeQuery::add_value(const T& value, InvertedInde } case InvertedIndexQueryType::LESS_THAN_QUERY: { + _high_value = &value; _high_value_encoded.clear(); _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); break; } case InvertedIndexQueryType::LESS_EQUAL_QUERY: { + _high_value = &value; _inclusive_high = true; _high_value_encoded.clear(); _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); break; } case InvertedIndexQueryType::EQUAL_QUERY: { + _high_value = _low_value = &value; _high_value_encoded.clear(); _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); _low_value_encoded.clear(); diff --git a/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.h b/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.h index 0224a5119bbd249..07c6e75429ef4fb 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.h +++ b/be/src/olap/rowset/segment_v2/inverted_index/query/inverted_index_query.h @@ -88,7 +88,7 @@ class InvertedIndexPointQueryI : public InvertedIndexQueryBase { LOG_FATAL("Execution reached an undefined behavior code path in InvertedIndexPointQueryI"); __builtin_unreachable(); } - [[nodiscard]] virtual std::vector get_values() const { + [[nodiscard]] virtual const std::vector& get_values() const { LOG_FATAL("Execution reached an undefined behavior code path in InvertedIndexPointQueryI"); __builtin_unreachable(); }; @@ -122,7 +122,9 @@ class InvertedIndexPointQuery : public InvertedIndexPointQueryI { } return result; } - [[nodiscard]] std::vector get_values() const override { return _values_encoded; }; + [[nodiscard]] const std::vector& get_values() const override { + return _values_encoded; + }; [[nodiscard]] PredicateType get_predicate_type() const override { return PT; }; [[nodiscard]] InvertedIndexQueryType get_query_type() const override { return _type; }; @@ -146,6 +148,8 @@ class InvertedIndexRangeQueryI : public InvertedIndexQueryBase { ~InvertedIndexRangeQueryI() override = default; [[nodiscard]] virtual const std::string& get_low_value() const = 0; [[nodiscard]] virtual const std::string& get_high_value() const = 0; + virtual bool low_value_is_null() = 0; + virtual bool high_value_is_null() = 0; QueryCategory get_query_category() override { return QueryCategory::RANGE_QUERY; } std::string to_string() override { LOG_FATAL("Execution reached an undefined behavior code path in InvertedIndexRangeQueryI"); @@ -208,6 +212,8 @@ class InvertedIndexRangeQuery : public InvertedIndexRangeQueryI { [[nodiscard]] const std::string& get_high_value() const override { return _high_value_encoded; }; + bool low_value_is_null() override { return _low_value == nullptr; }; + bool high_value_is_null() override { return _high_value == nullptr; }; std::string to_string() override { std::string low_op = _inclusive_low ? ">=" : ">"; std::string high_op = _inclusive_high ? "<=" : "<"; @@ -218,6 +224,8 @@ class InvertedIndexRangeQuery : public InvertedIndexRangeQueryI { [[nodiscard]] bool is_high_value_inclusive() const override { return _inclusive_high; } private: + const T* _low_value {}; + const T* _high_value {}; std::string _low_value_encoded {}; std::string _high_value_encoded {}; diff --git a/be/src/olap/rowset/segment_v2/inverted_index_reader.cpp b/be/src/olap/rowset/segment_v2/inverted_index_reader.cpp index 465561a6c7400fd..c5ae4d4b26c0b4b 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index_reader.cpp +++ b/be/src/olap/rowset/segment_v2/inverted_index_reader.cpp @@ -472,13 +472,18 @@ Status StringTypeInvertedIndexReader::handle_range_query(const std::string& colu nullptr, [](lucene::index::Term* term) { _CLDECDELETE(term); }); std::wstring column_name_ws = std::wstring(column_name.begin(), column_name.end()); + if (query->low_value_is_null() && query->high_value_is_null()) { + return Status::Error( + "StringTypeInvertedIndexReader::handle_range_query error: both low_value and " + "high_value is null"); + } auto search_low = query->get_low_value(); - if (!search_low.empty()) { + if (!query->low_value_is_null()) { std::wstring search_low_ws = StringUtil::string_to_wstring(search_low); low_term.reset(_CLNEW lucene::index::Term(column_name_ws.c_str(), search_low_ws.c_str())); } auto search_high = query->get_high_value(); - if (!search_high.empty()) { + if (!query->high_value_is_null()) { std::wstring search_high_ws = StringUtil::string_to_wstring(search_high); high_term.reset(_CLNEW lucene::index::Term(column_name_ws.c_str(), search_high_ws.c_str())); } @@ -784,7 +789,7 @@ InvertedIndexVisitor::InvertedIndexVisitor(roaring::Roaring* h, InvertedIndexQue } } else if (query_value->get_query_category() == QueryCategory::POINT_QUERY) { auto point_query = reinterpret_cast(query_value); - for (auto v : point_query->get_values()) { + for (const std::string& v : point_query->get_values()) { query_points.emplace_back(v); } // =1 equals 1<= && >=1