Merge pull request #37653 from vdimir/cross_join_dup_col_names

This commit is contained in:
Vladimir C 2022-05-31 17:50:19 +02:00 committed by GitHub
commit 2a38fdb796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -707,6 +707,13 @@ namespace
void HashJoin::initRightBlockStructure(Block & saved_block_sample)
{
if (isCrossOrComma(kind))
{
/// cross join doesn't have keys, just add all columns
saved_block_sample = sample_block_with_columns_to_add.cloneEmpty();
return;
}
bool multiple_disjuncts = !table_join->oneDisjunct();
/// We could remove key columns for LEFT | INNER HashJoin but we should keep them for JoinSwitcher (if any).
bool save_key_columns = !table_join->forceHashJoin() || isRightOrFull(kind) || multiple_disjuncts;
@ -724,9 +731,7 @@ void HashJoin::initRightBlockStructure(Block & saved_block_sample)
for (auto & column : sample_block_with_columns_to_add)
{
if (!saved_block_sample.findByName(column.name))
{
saved_block_sample.insert(column);
}
}
}

View File

@ -1184,7 +1184,7 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
if (remove_duplicates)
renameDuplicatedColumns(select_query);
/// Perform it before analyzing JOINs, because it may change number of columns with names unique and break some login inside JOINs
/// Perform it before analyzing JOINs, because it may change number of columns with names unique and break some logic inside JOINs
if (settings.optimize_normalize_count_variants)
TreeOptimizer::optimizeCountConstantAndSumOne(query);

View File

@ -0,0 +1,2 @@
\N
\N

View File

@ -0,0 +1,16 @@
-- Tags: no-backward-compatibility-check
-- https://github.com/ClickHouse/ClickHouse/issues/37561
SELECT NULL
FROM
(SELECT NULL) AS s1,
(SELECT count(2), count(1)) AS s2
;
SELECT NULL
FROM
(SELECT NULL) AS s1,
(SELECT count(2.), 9223372036854775806, count('-1'), NULL) AS s2,
(SELECT count('-2147483648')) AS any_query, (SELECT NULL) AS check_single_query
;