mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Merge pull request #60026 from Algunenano/fix_optimize_uniq_to_count
Fix optimize_uniq_to_count removing the column alias
This commit is contained in:
commit
586c1e9b4e
@ -156,7 +156,11 @@ void RewriteUniqToCountMatcher::visit(ASTPtr & ast, Data & /*data*/)
|
||||
};
|
||||
|
||||
if (match_subquery_with_distinct() || match_subquery_with_group_by())
|
||||
{
|
||||
auto main_alias = expr_list->children[0]->tryGetAlias();
|
||||
expr_list->children[0] = makeASTFunction("count");
|
||||
expr_list->children[0]->setAlias(main_alias);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,2 @@
|
||||
1
|
||||
1
|
@ -0,0 +1,37 @@
|
||||
--https://github.com/ClickHouse/ClickHouse/issues/59999
|
||||
DROP TABLE IF EXISTS tags;
|
||||
CREATE TABLE tags (dev_tag String) ENGINE = Memory AS SELECT '1';
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
(
|
||||
SELECT countDistinct(dev_tag) AS total_devtags
|
||||
FROM
|
||||
(
|
||||
SELECT dev_tag
|
||||
FROM
|
||||
(
|
||||
SELECT *
|
||||
FROM tags
|
||||
) AS t
|
||||
GROUP BY dev_tag
|
||||
) AS t
|
||||
) SETTINGS optimize_uniq_to_count=0;
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
(
|
||||
SELECT countDistinct(dev_tag) AS total_devtags
|
||||
FROM
|
||||
(
|
||||
SELECT dev_tag
|
||||
FROM
|
||||
(
|
||||
SELECT *
|
||||
FROM tags
|
||||
) AS t
|
||||
GROUP BY dev_tag
|
||||
) AS t
|
||||
) SETTINGS optimize_uniq_to_count=1;
|
||||
|
||||
DROP TABLE IF EXISTS tags;
|
Loading…
Reference in New Issue
Block a user