[fix](expr) fix performance problem caused by too many virtual function call (#28508)

This commit is contained in:
TengJianPing
2023-12-18 12:01:55 +08:00
committed by GitHub
parent 1223f62ce1
commit 9ebacb1faa
14 changed files with 153 additions and 46 deletions

View File

@ -840,6 +840,8 @@ template <template <typename, typename> class Operation, typename Name, bool is_
class FunctionBinaryArithmetic : public IFunction {
using OpTraits = OperationTraits<Operation>;
mutable bool need_replace_null_data_to_default_ = false;
template <typename F>
static bool cast_type(const IDataType* type, F&& f) {
return cast_type_to_either<DataTypeUInt8, DataTypeInt8, DataTypeInt16, DataTypeInt32,
@ -875,6 +877,10 @@ public:
String get_name() const override { return name; }
bool need_replace_null_data_to_default() const override {
return need_replace_null_data_to_default_;
}
size_t get_number_of_arguments() const override { return 2; }
DataTypes get_variadic_argument_types_impl() const override {
@ -894,6 +900,10 @@ public:
typename BinaryOperationTraits<Operation, LeftDataType,
RightDataType>::ResultDataType;
if constexpr (!std::is_same_v<ResultDataType, InvalidType>) {
need_replace_null_data_to_default_ =
IsDataTypeDecimal<ResultDataType> ||
(name == "pow" &&
std::is_floating_point_v<typename ResultDataType::FieldType>);
if constexpr (IsDataTypeDecimal<LeftDataType> &&
IsDataTypeDecimal<RightDataType>) {
type_res = decimal_result_type(left, right, OpTraits::is_multiply,