Skip to content

Commit

Permalink
Merge pull request ClickHouse#44469 from Avogar/low-card-if
Browse files Browse the repository at this point in the history
Don't execute and/or/if/multiIf on LowCardinality dictionary
  • Loading branch information
Avogar authored and Enmk committed Jun 28, 2023
1 parent e8e4192 commit a3428f0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Functions/FunctionsLogical.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class FunctionAnyArityLogical : public IFunction
ColumnPtr executeShortCircuit(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const;
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
size_t getNumberOfArguments() const override { return 0; }
bool canBeExecutedOnLowCardinalityDictionary() const override { return false; }

bool useDefaultImplementationForNulls() const override { return !Impl::specialImplementationForNulls(); }

Expand Down
1 change: 1 addition & 0 deletions src/Functions/if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ class FunctionIf : public FunctionIfBase
}
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t /*number_of_arguments*/) const override { return {0}; }
bool canBeExecutedOnLowCardinalityDictionary() const override { return false; }

/// Get result types by argument types. If the function does not apply to these arguments, throw an exception.
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
Expand Down
1 change: 1 addition & 0 deletions src/Functions/multiIf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FunctionMultiIf final : public FunctionIfBase
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
size_t getNumberOfArguments() const override { return 0; }
bool useDefaultImplementationForNulls() const override { return false; }
bool canBeExecutedOnLowCardinalityDictionary() const override { return false; }

ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t number_of_arguments) const override
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create table if not exists t (`arr.key` Array(LowCardinality(String)), `arr.value` Array(LowCardinality(String))) engine = Memory;
insert into t (`arr.key`, `arr.value`) values (['a'], ['b']);
select if(true, if(lowerUTF8(arr.key) = 'a', 1, 2), 3) as x from t left array join arr;
drop table t;

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
UInt8
UInt8
UInt8
UInt8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select toTypeName(if(toLowCardinality(number % 2), 1, 2)) from numbers(1);
select toTypeName(multiIf(toLowCardinality(number % 2), 1, 1, 2, 3)) from numbers(1);
select toTypeName(toLowCardinality(number % 2) and 2) from numbers(1);
select toTypeName(toLowCardinality(number % 2) or 2) from numbers(1);

0 comments on commit a3428f0

Please sign in to comment.