Skip to content

Commit

Permalink
Fix expression on integer overflow case (#25320)
Browse files Browse the repository at this point in the history
Signed-off-by: longjiquan <jiquan.long@zilliz.com>
  • Loading branch information
longjiquan committed Jul 5, 2023
1 parent 3117372 commit c2a2ece
Show file tree
Hide file tree
Showing 3 changed files with 650 additions and 7 deletions.
17 changes: 10 additions & 7 deletions internal/core/src/query/visitors/ExecExprVisitor.cpp
Expand Up @@ -589,7 +589,10 @@ auto
ExecExprVisitor::ExecBinaryArithOpEvalRangeVisitorDispatcher(
BinaryArithOpEvalRangeExpr& expr_raw) -> BitsetType {
// see also: https://github.com/milvus-io/milvus/issues/23646.
typedef std::conditional_t<std::is_integral_v<T>, int64_t, T>
typedef std::conditional_t<std::is_integral_v<T> &&
!std::is_same_v<bool, T>,
int64_t,
T>
HighPrecisionType;

auto& expr =
Expand Down Expand Up @@ -940,22 +943,22 @@ ExecExprVisitor::ExecBinaryRangeVisitorDispatcher(BinaryRangeExpr& expr_raw)
conditional_t<std::is_same_v<T, std::string_view>, std::string, T>
IndexInnerType;
using Index = index::ScalarIndex<IndexInnerType>;
auto& expr = static_cast<BinaryRangeExprImpl<IndexInnerType>&>(expr_raw);

bool lower_inclusive = expr.lower_inclusive_;
bool upper_inclusive = expr.upper_inclusive_;

// see also: https://github.com/milvus-io/milvus/issues/23646.
typedef std::conditional_t<std::is_integral_v<IndexInnerType>,
typedef std::conditional_t<std::is_integral_v<IndexInnerType> &&
!std::is_same_v<bool, T>,
int64_t,
IndexInnerType>
HighPrecisionType;
auto& expr = static_cast<BinaryRangeExprImpl<HighPrecisionType>&>(expr_raw);

bool lower_inclusive = expr.lower_inclusive_;
bool upper_inclusive = expr.upper_inclusive_;
auto val1 = static_cast<HighPrecisionType>(expr.lower_value_);
auto val2 = static_cast<HighPrecisionType>(expr.upper_value_);

auto index_func = [&](Index* index) {
if constexpr (std::is_integral_v<T>) {
if constexpr (std::is_integral_v<T> && !std::is_same_v<bool, T>) {
if (gt_ub<T>(val1)) {
return TargetBitmap(index->Size(), false);
} else if (lt_lb<T>(val1)) {
Expand Down
1 change: 1 addition & 0 deletions internal/core/unittest/CMakeLists.txt
Expand Up @@ -50,6 +50,7 @@ set(MILVUS_TEST_FILES
test_tracer.cpp
test_local_chunk_manager.cpp
test_disk_file_manager_test.cpp
test_integer_overflow.cpp
)

if ( BUILD_DISK_ANN STREQUAL "ON" )
Expand Down

0 comments on commit c2a2ece

Please sign in to comment.