mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Trivial optimize of function coalesce. (#59627)
* reuse result of functionfactory::get * add perf test * Update src/Functions/coalesce.cpp Co-authored-by: János Benjamin Antal <antaljanosbenjamin@users.noreply.github.com> * change as requested --------- Co-authored-by: János Benjamin Antal <antaljanosbenjamin@users.noreply.github.com>
This commit is contained in:
parent
a7c2d3146c
commit
90d07ba82c
@ -29,7 +29,14 @@ public:
|
||||
return std::make_shared<FunctionCoalesce>(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;
|
||||
};
|
||||
|
||||
}
|
||||
|
3
tests/performance/coalesce.xml
Normal file
3
tests/performance/coalesce.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<test>
|
||||
<query>select coalesce(materialize(null), -1) from numbers(1000000000) format Null settings max_block_size = 8192</query>
|
||||
</test>
|
Loading…
Reference in New Issue
Block a user