diff --git a/src/Functions/coalesce.cpp b/src/Functions/coalesce.cpp index befebd1ff52..4ae90a9db13 100644 --- a/src/Functions/coalesce.cpp +++ b/src/Functions/coalesce.cpp @@ -29,7 +29,14 @@ public: return std::make_shared(context); } - explicit FunctionCoalesce(ContextPtr context_) : context(context_) {} + explicit FunctionCoalesce(ContextPtr context_) + : context(context_) + , is_not_null(FunctionFactory::instance().get("isNotNull", context)) + , assume_not_null(FunctionFactory::instance().get("assumeNotNull", context)) + , if_function(FunctionFactory::instance().get("if", context)) + , multi_if_function(FunctionFactory::instance().get("multiIf", context)) + { + } std::string getName() const override { @@ -110,8 +117,6 @@ public: break; } - auto is_not_null = FunctionFactory::instance().get("isNotNull", context); - auto assume_not_null = FunctionFactory::instance().get("assumeNotNull", context); ColumnsWithTypeAndName multi_if_args; ColumnsWithTypeAndName tmp_args(1); @@ -146,13 +151,8 @@ public: /// If there was only two arguments (3 arguments passed to multiIf) /// use function "if" instead, because it's implemented more efficient. /// TODO: make "multiIf" the same efficient. - FunctionOverloadResolverPtr if_function; - if (multi_if_args.size() == 3) - if_function = FunctionFactory::instance().get("if", context); - else - if_function = FunctionFactory::instance().get("multiIf", context); - - ColumnPtr res = if_function->build(multi_if_args)->execute(multi_if_args, result_type, input_rows_count); + FunctionOverloadResolverPtr if_or_multi_if = multi_if_args.size() == 3 ? if_function : multi_if_function; + ColumnPtr res = if_or_multi_if->build(multi_if_args)->execute(multi_if_args, result_type, input_rows_count); /// if last argument is not nullable, result should be also not nullable if (!multi_if_args.back().column->isNullable() && res->isNullable()) @@ -170,6 +170,10 @@ public: private: ContextPtr context; + FunctionOverloadResolverPtr is_not_null; + FunctionOverloadResolverPtr assume_not_null; + FunctionOverloadResolverPtr if_function; + FunctionOverloadResolverPtr multi_if_function; }; } diff --git a/tests/performance/coalesce.xml b/tests/performance/coalesce.xml new file mode 100644 index 00000000000..08b9a6aab1e --- /dev/null +++ b/tests/performance/coalesce.xml @@ -0,0 +1,3 @@ + + select coalesce(materialize(null), -1) from numbers(1000000000) format Null settings max_block_size = 8192 +