Merge pull request #61847 from ClickHouse/fix-distinct-in-subquery-analyzer

Fix: DISTINCT in subquery with analyzer
This commit is contained in:
Alexey Milovidov 2024-03-25 05:32:48 +03:00 committed by GitHub
commit f9bff8bd79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View File

@ -148,6 +148,13 @@ void RemoveUnusedProjectionColumnsPass::run(QueryTreeNodePtr & query_tree_node,
for (auto & [query_or_union_node, used_columns] : visitor.query_or_union_node_to_used_columns)
{
/// can't remove columns from distinct, see example - 03023_remove_unused_column_distinct.sql
if (auto * query_node = query_or_union_node->as<QueryNode>())
{
if (query_node->isDistinct())
continue;
}
auto used_projection_indexes = convertUsedColumnNamesToUsedProjectionIndexes(query_or_union_node, used_columns);
updateUsedProjectionIndexes(query_or_union_node, used_projection_indexes);

View File

@ -0,0 +1,6 @@
product_0
product_1
product_0
product_1
product_0
product_1

View File

@ -0,0 +1,15 @@
SELECT product_id
FROM
(
SELECT DISTINCT
product_id,
section_id
FROM
(
SELECT
concat('product_', number % 2) AS product_id,
concat('section_', number % 3) AS section_id
FROM numbers(10)
)
)
SETTINGS allow_experimental_analyzer = 1;