From a7129332af1bab72e17fb4b2b73bb03e586021af Mon Sep 17 00:00:00 2001 From: avogar Date: Tue, 20 Dec 2022 22:07:59 +0000 Subject: [PATCH 1/2] Don't execute and/or/if/multiIf on LowCardinality dictionary --- src/Functions/FunctionsLogical.h | 1 + src/Functions/if.cpp | 1 + src/Functions/multiIf.cpp | 1 + .../02514_if_with_lazy_low_cardinality.reference | 1 + .../0_stateless/02514_if_with_lazy_low_cardinality.sql | 5 +++++ .../02515_and_or_if_multiif_not_return_lc.reference | 4 ++++ .../0_stateless/02515_and_or_if_multiif_not_return_lc.sql | 6 ++++++ 7 files changed, 19 insertions(+) create mode 100644 tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.reference create mode 100644 tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.sql create mode 100644 tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.reference create mode 100644 tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql diff --git a/src/Functions/FunctionsLogical.h b/src/Functions/FunctionsLogical.h index 30d8983b8cc..833191866e5 100644 --- a/src/Functions/FunctionsLogical.h +++ b/src/Functions/FunctionsLogical.h @@ -176,6 +176,7 @@ public: 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(); } diff --git a/src/Functions/if.cpp b/src/Functions/if.cpp index 0baf64c83d9..049e6d24920 100644 --- a/src/Functions/if.cpp +++ b/src/Functions/if.cpp @@ -1026,6 +1026,7 @@ public: } 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 diff --git a/src/Functions/multiIf.cpp b/src/Functions/multiIf.cpp index f658528a2a7..37301037c0e 100644 --- a/src/Functions/multiIf.cpp +++ b/src/Functions/multiIf.cpp @@ -51,6 +51,7 @@ public: size_t getNumberOfArguments() const override { return 0; } bool useDefaultImplementationForNulls() const override { return false; } bool useDefaultImplementationForNothing() const override { return false; } + bool canBeExecutedOnLowCardinalityDictionary() const override { return false; } ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t number_of_arguments) const override { diff --git a/tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.reference b/tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.sql b/tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.sql new file mode 100644 index 00000000000..80e3c0a9ece --- /dev/null +++ b/tests/queries/0_stateless/02514_if_with_lazy_low_cardinality.sql @@ -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; + diff --git a/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.reference b/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.reference new file mode 100644 index 00000000000..805bbdf7a59 --- /dev/null +++ b/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.reference @@ -0,0 +1,4 @@ +UInt8 +UInt8 +UInt8 +UInt8 diff --git a/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql b/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql new file mode 100644 index 00000000000..f5ac870cdfe --- /dev/null +++ b/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql @@ -0,0 +1,6 @@ +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); + + From 4f376308b633a9534cc9e090d8d7f2203a11a739 Mon Sep 17 00:00:00 2001 From: avogar Date: Tue, 20 Dec 2022 22:09:49 +0000 Subject: [PATCH 2/2] Remove extra line --- .../0_stateless/02515_and_or_if_multiif_not_return_lc.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql b/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql index f5ac870cdfe..0ccccd4d9a7 100644 --- a/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql +++ b/tests/queries/0_stateless/02515_and_or_if_multiif_not_return_lc.sql @@ -3,4 +3,3 @@ select toTypeName(multiIf(toLowCardinality(number % 2), 1, 1, 2, 3)) from number select toTypeName(toLowCardinality(number % 2) and 2) from numbers(1); select toTypeName(toLowCardinality(number % 2) or 2) from numbers(1); -