mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
Issue: #31285 Basically, I've replaced `FixedVector<bool>` and `boost::dynamic_bitset` with custom bitset and bitsetview in order to reduce the memory bandwidth & increase performance for the filtering. This PR is for internal use only. Current progress (numbers are for GCC 9.5.0 on Ubuntu 22.04 LTS; clang-17 produces better performance numbers): Baseline: ``` [ RUN ] CApiTest.AssembeChunkPerfTest start test cost: 17903us [ OK ] CApiTest.AssembeChunkPerfTest (183 ms) [ RUN ] Expr.TestMultiLogicalExprsOptimization cost: 1391us cost: 5us cost: 4us cost: 4us cost: 6us cost: 4us cost: 4us cost: 4us cost: 4us cost: 4us 143 cost: 10us cost: 8us cost: 10us cost: 8us cost: 8us cost: 8us cost: 8us cost: 8us cost: 8us cost: 9us 8 /home/ubuntu/zilliz/milvus4/milvus/internal/core/unittest/test_expr.cpp:1561: Failure Expected: (cost_op) < (cost_no_op), actual: 143 vs 8 [ FAILED ] Expr.TestMultiLogicalExprsOptimization (7 ms) [ RUN ] Expr.TestExprs start test 3cost: 889us start test 10cost: 2us start test 20cost: 2us start test 30cost: 2us start test 50cost: 3us start test 100cost: 7us start test 200cost: 16us [ OK ] Expr.TestExprs (9 ms) [ RUN ] Expr.TestUnaryBenchTest start test type:2 cost: 124.8us start test type:3 cost: 163.1us start test type:4 cost: 275.9us start test type:5 cost: 590.9us start test type:10 cost: 62.7us start test type:11 cost: 65.9us [ OK ] Expr.TestUnaryBenchTest (1153 ms) [ RUN ] Expr.TestBinaryRangeBenchTest start test type:2 cost: 151.4us start test type:3 cost: 198.4us start test type:4 cost: 361.9us start test type:5 cost: 753.9us start test type:10 cost: 64.6us start test type:11 cost: 62.2us [ OK ] Expr.TestBinaryRangeBenchTest (1151 ms) [ RUN ] Expr.TestLogicalUnaryBenchTest start test type:2 cost: 121.14us start test type:3 cost: 156.84us start test type:4 cost: 249.76us start test type:5 cost: 534.44us start test type:10 cost: 82.2us start test type:11 cost: 83.52us [ OK ] Expr.TestLogicalUnaryBenchTest (1202 ms) [ RUN ] Expr.TestBinaryLogicalBenchTest start test type:2 cost: 80.64us start test type:3 cost: 78.22us start test type:4 cost: 255.76us start test type:5 cost: 532.04us start test type:10 cost: 89.26us start test type:11 cost: 90us [ OK ] Expr.TestBinaryLogicalBenchTest (1198 ms) [ RUN ] Expr.TestBinaryArithOpEvalRangeBenchExpr start test type:2 cost: 401.7us start test type:3 cost: 420.96us start test type:4 cost: 418.04us start test type:5 cost: 470.54us start test type:10 cost: 250.32us start test type:11 cost: 850.08us [ OK ] Expr.TestBinaryArithOpEvalRangeBenchExpr (1273 ms) [ RUN ] Expr.TestCompareExprBenchTest start test type:2 cost: 162us start test type:3 cost: 142us start test type:4 cost: 374us start test type:5 cost: 674us start test type:10 cost: 366us start test type:11 cost: 645us [ OK ] Expr.TestCompareExprBenchTest (1214 ms) [ RUN ] Expr.TestRefactorExprs start test 3cost: 1253us start test 10cost: 1060us start test 20cost: 681us start test 30cost: 522us start test 50cost: 511us start test 100cost: 506us start test 200cost: 497us [ OK ] Expr.TestRefactorExprs (1142 ms) ``` Candidate: ``` [ RUN ] CApiTest.AssembeChunkPerfTest start test cost: 6099us [ OK ] CApiTest.AssembeChunkPerfTest (153 ms) [ RUN ] Expr.TestMultiLogicalExprsOptimization cost: 42us cost: 15us cost: 15us cost: 14us cost: 15us cost: 15us cost: 15us cost: 15us cost: 15us cost: 15us 17 cost: 41us cost: 39us cost: 33us cost: 33us cost: 33us cost: 33us cost: 34us cost: 41us cost: 34us cost: 34us 35 [ OK ] Expr.TestMultiLogicalExprsOptimization (6 ms) [ RUN ] Expr.TestExprs start test 3cost: 20us start test 10cost: 2us start test 20cost: 2us start test 30cost: 2us start test 50cost: 4us start test 100cost: 8us start test 200cost: 15us [ OK ] Expr.TestExprs (8 ms) [ RUN ] Expr.TestUnaryBenchTest start test type:2 cost: 55.7us start test type:3 cost: 79.8us start test type:4 cost: 177.6us start test type:5 cost: 337.2us start test type:10 cost: 16.9us start test type:11 cost: 15.7us [ OK ] Expr.TestUnaryBenchTest (1140 ms) [ RUN ] Expr.TestBinaryRangeBenchTest start test type:2 cost: 57.1us start test type:3 cost: 87us start test type:4 cost: 177.5us start test type:5 cost: 342.7us start test type:10 cost: 17.9us start test type:11 cost: 16.7us [ OK ] Expr.TestBinaryRangeBenchTest (1152 ms) [ RUN ] Expr.TestLogicalUnaryBenchTest start test type:2 cost: 34.58us start test type:3 cost: 68.86us start test type:4 cost: 151.38us start test type:5 cost: 286.8us start test type:10 cost: 16.54us start test type:11 cost: 16.7us [ OK ] Expr.TestLogicalUnaryBenchTest (1165 ms) [ RUN ] Expr.TestBinaryLogicalBenchTest start test type:2 cost: 20us start test type:3 cost: 17.1us start test type:4 cost: 154.12us start test type:5 cost: 286.1us start test type:10 cost: 19.6us start test type:11 cost: 19.24us [ OK ] Expr.TestBinaryLogicalBenchTest (1188 ms) [ RUN ] Expr.TestBinaryArithOpEvalRangeBenchExpr start test type:2 cost: 125.7us start test type:3 cost: 111.34us start test type:4 cost: 148.02us start test type:5 cost: 306.7us start test type:10 cost: 149.3us start test type:11 cost: 282.94us [ OK ] Expr.TestBinaryArithOpEvalRangeBenchExpr (1221 ms) [ RUN ] Expr.TestCompareExprBenchTest start test type:2 cost: 89us start test type:3 cost: 79us start test type:4 cost: 323us start test type:5 cost: 629us start test type:10 cost: 313us start test type:11 cost: 591us [ OK ] Expr.TestCompareExprBenchTest (1228 ms) [ RUN ] Expr.TestRefactorExprs start test 3cost: 874us start test 10cost: 611us start test 20cost: 290us start test 30cost: 294us start test 50cost: 272us start test 100cost: 278us start test 200cost: 279us [ OK ] Expr.TestRefactorExprs (1149 ms) ``` Signed-off-by: Alexandr Guzhva <alexanderguzhva@gmail.com>
477 lines
21 KiB
C++
477 lines
21 KiB
C++
// Licensed to the LF AI & Data foundation under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <fmt/core.h>
|
|
|
|
#include "common/EasyAssert.h"
|
|
#include "common/Types.h"
|
|
#include "common/Vector.h"
|
|
#include "exec/expression/Expr.h"
|
|
#include "segcore/SegmentInterface.h"
|
|
|
|
namespace milvus {
|
|
namespace exec {
|
|
|
|
namespace {
|
|
|
|
template <proto::plan::OpType cmp_op>
|
|
struct CmpOpHelper {
|
|
using op = void;
|
|
};
|
|
template <>
|
|
struct CmpOpHelper<proto::plan::OpType::Equal> {
|
|
static constexpr auto op = milvus::bitset::CompareOpType::EQ;
|
|
};
|
|
template <>
|
|
struct CmpOpHelper<proto::plan::OpType::GreaterEqual> {
|
|
static constexpr auto op = milvus::bitset::CompareOpType::GE;
|
|
};
|
|
template <>
|
|
struct CmpOpHelper<proto::plan::OpType::GreaterThan> {
|
|
static constexpr auto op = milvus::bitset::CompareOpType::GT;
|
|
};
|
|
template <>
|
|
struct CmpOpHelper<proto::plan::OpType::LessEqual> {
|
|
static constexpr auto op = milvus::bitset::CompareOpType::LE;
|
|
};
|
|
template <>
|
|
struct CmpOpHelper<proto::plan::OpType::LessThan> {
|
|
static constexpr auto op = milvus::bitset::CompareOpType::LT;
|
|
};
|
|
template <>
|
|
struct CmpOpHelper<proto::plan::OpType::NotEqual> {
|
|
static constexpr auto op = milvus::bitset::CompareOpType::NE;
|
|
};
|
|
|
|
template <proto::plan::ArithOpType arith_op>
|
|
struct ArithOpHelper {
|
|
using op = void;
|
|
};
|
|
template <>
|
|
struct ArithOpHelper<proto::plan::ArithOpType::Add> {
|
|
static constexpr auto op = milvus::bitset::ArithOpType::Add;
|
|
};
|
|
template <>
|
|
struct ArithOpHelper<proto::plan::ArithOpType::Sub> {
|
|
static constexpr auto op = milvus::bitset::ArithOpType::Sub;
|
|
};
|
|
template <>
|
|
struct ArithOpHelper<proto::plan::ArithOpType::Mul> {
|
|
static constexpr auto op = milvus::bitset::ArithOpType::Mul;
|
|
};
|
|
template <>
|
|
struct ArithOpHelper<proto::plan::ArithOpType::Div> {
|
|
static constexpr auto op = milvus::bitset::ArithOpType::Div;
|
|
};
|
|
template <>
|
|
struct ArithOpHelper<proto::plan::ArithOpType::Mod> {
|
|
static constexpr auto op = milvus::bitset::ArithOpType::Mod;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
template <typename T,
|
|
proto::plan::OpType cmp_op,
|
|
proto::plan::ArithOpType arith_op>
|
|
struct ArithOpElementFunc {
|
|
typedef std::conditional_t<std::is_integral_v<T> &&
|
|
!std::is_same_v<bool, T>,
|
|
int64_t,
|
|
T>
|
|
HighPrecisonType;
|
|
void
|
|
operator()(const T* src,
|
|
size_t size,
|
|
HighPrecisonType val,
|
|
HighPrecisonType right_operand,
|
|
TargetBitmapView res) {
|
|
/*
|
|
// This is the original code, kept here for the documentation purposes
|
|
for (int i = 0; i < size; ++i) {
|
|
if constexpr (cmp_op == proto::plan::OpType::Equal) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (src[i] + right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (src[i] - right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (src[i] * right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (src[i] / right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] = (fmod(src[i], right_operand)) == val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::NotEqual) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (src[i] + right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (src[i] - right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (src[i] * right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (src[i] / right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] = (fmod(src[i], right_operand)) != val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::GreaterThan) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (src[i] + right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (src[i] - right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (src[i] * right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (src[i] / right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] = (fmod(src[i], right_operand)) > val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::GreaterEqual) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (src[i] + right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (src[i] - right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (src[i] * right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (src[i] / right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] = (fmod(src[i], right_operand)) >= val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::LessThan) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (src[i] + right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (src[i] - right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (src[i] * right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (src[i] / right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] = (fmod(src[i], right_operand)) < val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::LessEqual) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (src[i] + right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (src[i] - right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (src[i] * right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (src[i] / right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] = (fmod(src[i], right_operand)) <= val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
|
|
if constexpr (!std::is_same_v<decltype(CmpOpHelper<cmp_op>::op),
|
|
void>) {
|
|
constexpr auto cmp_op_cvt = CmpOpHelper<cmp_op>::op;
|
|
if constexpr (!std::is_same_v<decltype(ArithOpHelper<arith_op>::op),
|
|
void>) {
|
|
constexpr auto arith_op_cvt = ArithOpHelper<arith_op>::op;
|
|
|
|
res.inplace_arith_compare<T, arith_op_cvt, cmp_op_cvt>(
|
|
src, right_operand, val, size);
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format("unsupported cmp type:{} for ArithOpElementFunc",
|
|
cmp_op));
|
|
}
|
|
}
|
|
};
|
|
|
|
template <typename T,
|
|
proto::plan::OpType cmp_op,
|
|
proto::plan::ArithOpType arith_op>
|
|
struct ArithOpIndexFunc {
|
|
typedef std::conditional_t<std::is_integral_v<T> &&
|
|
!std::is_same_v<bool, T>,
|
|
int64_t,
|
|
T>
|
|
HighPrecisonType;
|
|
using Index = index::ScalarIndex<T>;
|
|
TargetBitmap
|
|
operator()(Index* index,
|
|
size_t size,
|
|
HighPrecisonType val,
|
|
HighPrecisonType right_operand) {
|
|
TargetBitmap res(size);
|
|
for (size_t i = 0; i < size; ++i) {
|
|
if constexpr (cmp_op == proto::plan::OpType::Equal) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (index->Reverse_Lookup(i) + right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (index->Reverse_Lookup(i) - right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (index->Reverse_Lookup(i) * right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (index->Reverse_Lookup(i) / right_operand) == val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] =
|
|
(fmod(index->Reverse_Lookup(i), right_operand)) == val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::NotEqual) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (index->Reverse_Lookup(i) + right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (index->Reverse_Lookup(i) - right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (index->Reverse_Lookup(i) * right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (index->Reverse_Lookup(i) / right_operand) != val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] =
|
|
(fmod(index->Reverse_Lookup(i), right_operand)) != val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::GreaterThan) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (index->Reverse_Lookup(i) + right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (index->Reverse_Lookup(i) - right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (index->Reverse_Lookup(i) * right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (index->Reverse_Lookup(i) / right_operand) > val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] =
|
|
(fmod(index->Reverse_Lookup(i), right_operand)) > val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::GreaterEqual) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (index->Reverse_Lookup(i) + right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (index->Reverse_Lookup(i) - right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (index->Reverse_Lookup(i) * right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (index->Reverse_Lookup(i) / right_operand) >= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] =
|
|
(fmod(index->Reverse_Lookup(i), right_operand)) >= val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::LessThan) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (index->Reverse_Lookup(i) + right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (index->Reverse_Lookup(i) - right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (index->Reverse_Lookup(i) * right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (index->Reverse_Lookup(i) / right_operand) < val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] =
|
|
(fmod(index->Reverse_Lookup(i), right_operand)) < val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
} else if constexpr (cmp_op == proto::plan::OpType::LessEqual) {
|
|
if constexpr (arith_op == proto::plan::ArithOpType::Add) {
|
|
res[i] = (index->Reverse_Lookup(i) + right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Sub) {
|
|
res[i] = (index->Reverse_Lookup(i) - right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mul) {
|
|
res[i] = (index->Reverse_Lookup(i) * right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Div) {
|
|
res[i] = (index->Reverse_Lookup(i) / right_operand) <= val;
|
|
} else if constexpr (arith_op ==
|
|
proto::plan::ArithOpType::Mod) {
|
|
res[i] =
|
|
(fmod(index->Reverse_Lookup(i), right_operand)) <= val;
|
|
} else {
|
|
PanicInfo(
|
|
OpTypeInvalid,
|
|
fmt::format(
|
|
"unsupported arith type:{} for ArithOpElementFunc",
|
|
arith_op));
|
|
}
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
};
|
|
|
|
class PhyBinaryArithOpEvalRangeExpr : public SegmentExpr {
|
|
public:
|
|
PhyBinaryArithOpEvalRangeExpr(
|
|
const std::vector<std::shared_ptr<Expr>>& input,
|
|
const std::shared_ptr<const milvus::expr::BinaryArithOpEvalRangeExpr>&
|
|
expr,
|
|
const std::string& name,
|
|
const segcore::SegmentInternalInterface* segment,
|
|
int64_t active_count,
|
|
int64_t batch_size)
|
|
: SegmentExpr(std::move(input),
|
|
name,
|
|
segment,
|
|
expr->column_.field_id_,
|
|
active_count,
|
|
batch_size),
|
|
expr_(expr) {
|
|
}
|
|
|
|
void
|
|
Eval(EvalCtx& context, VectorPtr& result) override;
|
|
|
|
private:
|
|
template <typename T>
|
|
VectorPtr
|
|
ExecRangeVisitorImpl();
|
|
|
|
template <typename T>
|
|
VectorPtr
|
|
ExecRangeVisitorImplForIndex();
|
|
|
|
template <typename T>
|
|
VectorPtr
|
|
ExecRangeVisitorImplForData();
|
|
|
|
template <typename ValueType>
|
|
VectorPtr
|
|
ExecRangeVisitorImplForJson();
|
|
|
|
template <typename ValueType>
|
|
VectorPtr
|
|
ExecRangeVisitorImplForArray();
|
|
|
|
private:
|
|
std::shared_ptr<const milvus::expr::BinaryArithOpEvalRangeExpr> expr_;
|
|
};
|
|
} //namespace exec
|
|
} // namespace milvus
|