improve least/greatest by allow nullable numberic fields compare

This commit is contained in:
kevinyhzou 2024-05-31 16:44:31 +08:00
parent 0f23f9b384
commit 2a14168075
2 changed files with 11 additions and 1 deletions

View File

@ -111,7 +111,7 @@ public:
argument_types.push_back(argument.type); argument_types.push_back(argument.type);
/// More efficient specialization for two numeric arguments. /// More efficient specialization for two numeric arguments.
if (arguments.size() == 2 && isNumber(arguments[0].type) && isNumber(arguments[1].type)) if (arguments.size() == 2 && isNumber(removeNullable(arguments[0].type)) && isNumber(removeNullable(arguments[1].type)))
return std::make_unique<FunctionToFunctionBaseAdaptor>(SpecializedFunction::create(context), argument_types, return_type); return std::make_unique<FunctionToFunctionBaseAdaptor>(SpecializedFunction::create(context), argument_types, return_type);
return std::make_unique<FunctionToFunctionBaseAdaptor>( return std::make_unique<FunctionToFunctionBaseAdaptor>(

View File

@ -0,0 +1,10 @@
<test>
<create_query>CREATE TABLE test (id Int32, x1 Nullable(Int32), x2 Nullable(Float32)) ENGINE = MergeTree() ORDER BY id</create_query>
<fill_query>INSERT INTO test SELECT number, number+1, number + 2 FROM numbers(1000000)</fill_query>
<query tag='LEAST'>SELECT COUNT(1) FROM test WHERE least(x1, x2) > 1</query>
<query tag='GREATEST'>SELECT COUNT(1) FROM test WHERE GREATEST(x1, x2) > 1</query>
<drop_query>DROP TABLE IF EXISTS test</drop_query>
</test>