Skip to content

Commit fa0a023

Browse files
Backport #96405 to 25.12: Crash with old analyzer if JOIN and duplicated aliases
1 parent ce64240 commit fa0a023

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/Interpreters/TreeRewriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,14 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
13281328
result.analyzed_join = std::make_shared<TableJoin>();
13291329

13301330
if (remove_duplicates)
1331+
{
1332+
Aliases aliases;
1333+
NameSet name_set;
1334+
1335+
normalize(query, aliases, name_set, select_options.ignore_alias, settings, /* allow_self_aliases = */ true, getContext(), select_options.is_create_parameterized_view);
13311336
renameDuplicatedColumns(select_query);
1337+
}
1338+
13321339

13331340
/// Perform it before analyzing JOINs, because it may change number of columns with names unique and break some logic inside JOINs
13341341
if (settings[Setting::optimize_normalize_count_variants])
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
42
2+
1 g
3+
42
4+
1 g
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{% for enable_analyzer in [0, 1] -%}
2+
3+
SET enable_analyzer = {{ enable_analyzer }};
4+
SET join_algorithm = 'hash';
5+
6+
SELECT A.g
7+
FROM ( SELECT 1::Int8 AS d ) AS B
8+
JOIN ( SELECT 1::Int8 as d, g, 42::Int32 AS g FROM ( SELECT '128' AS g ) ) AS A
9+
USING (d);
10+
11+
WITH B AS (
12+
SELECT
13+
1 AS d
14+
),
15+
A AS (
16+
SELECT
17+
g, d,
18+
MAX(IF(m = 'A', g, NULL)) AS g
19+
FROM
20+
(
21+
SELECT
22+
'g' AS g, 1 d,
23+
'A' m
24+
)
25+
GROUP BY ALL )
26+
SELECT
27+
B.*,
28+
A.g
29+
FROM
30+
B
31+
LEFT JOIN A USING d;
32+
{% endfor -%}

0 commit comments

Comments
 (0)