Skip to content

Commit 177d513

Browse files
Backport ClickHouse#89870 to 25.8: Remove injective functions from GROUP BY regardless optimize_injective_functions_in_group_by in old analyzer for compatibility
1 parent ab23429 commit 177d513

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

src/Interpreters/TreeOptimizer.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ namespace Setting
6060
extern const SettingsBool optimize_redundant_functions_in_order_by;
6161
extern const SettingsBool optimize_rewrite_array_exists_to_has;
6262
extern const SettingsBool optimize_or_like_chain;
63-
extern const SettingsBool optimize_injective_functions_in_group_by;
6463
}
6564

6665
namespace ErrorCodes
@@ -133,12 +132,6 @@ void optimizeGroupBy(ASTSelectQuery * select_query, ContextPtr context)
133132
{
134133
if (const auto * function = group_exprs[i]->as<ASTFunction>())
135134
{
136-
if (!settings[Setting::optimize_injective_functions_in_group_by])
137-
{
138-
++i;
139-
continue;
140-
}
141-
142135
/// assert function is injective
143136
if (possibly_injective_function_names.contains(function->name))
144137
{

tests/queries/0_stateless/03641_group_by_injective_functoon_bad_arguments.reference

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
1 str
22
1 str
3-
1 str
43
QUERY id: 0
54
PROJECTION COLUMNS
65
count() UInt64

tests/queries/0_stateless/03641_group_by_injective_functoon_bad_arguments.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
create table test (json JSON) engine=MergeTree order by tuple();
22
insert into test select '{"a" : "str"}';
3-
select count(), toString(json.a) from test group by toString(json.a) settings enable_analyzer=0, optimize_injective_functions_in_group_by=0;
3+
4+
-- This won't work, see https://github.com/ClickHouse/ClickHouse/issues/89854
5+
-- select count(), toString(json.a) from test group by toString(json.a) settings enable_analyzer=0, optimize_injective_functions_in_group_by=0;
6+
47
select count(), toString(json.a) from test group by toString(json.a) settings enable_analyzer=1, optimize_injective_functions_in_group_by=0;
58
select count(), toString(json.a) from test group by toString(json.a) settings enable_analyzer=1, optimize_injective_functions_in_group_by=1;
69
explain query tree select count(), toString(json.a) from test group by toString(json.a) settings enable_analyzer=1, optimize_injective_functions_in_group_by=1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a_0 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT
2+
concat('a_', toString(number % 3)) AS a,
3+
number % 5 AS b
4+
FROM numbers(50)
5+
GROUP BY (a, b)
6+
ORDER BY (a, b)
7+
LIMIT 1
8+
SETTINGS optimize_injective_functions_in_group_by = 0, enable_analyzer = 0;

0 commit comments

Comments
 (0)