Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expression on integer overflow case #25320

Merged
merged 1 commit into from Jul 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -51,6 +51,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