From 62153e7030f28415d0ea69c7949917f47961529f Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Wed, 12 May 2021 02:30:16 +0800 Subject: [PATCH] Fix --- src/Interpreters/QueryNormalizer.cpp | 12 +----------- .../01764_prefer_column_name_to_alias.reference | 2 ++ .../01764_prefer_column_name_to_alias.sql | 10 ++++++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Interpreters/QueryNormalizer.cpp b/src/Interpreters/QueryNormalizer.cpp index 0a2e6505558..c206810e9e2 100644 --- a/src/Interpreters/QueryNormalizer.cpp +++ b/src/Interpreters/QueryNormalizer.cpp @@ -138,18 +138,8 @@ void QueryNormalizer::visit(ASTSelectQuery & select, const ASTPtr &, Data & data { for (auto & child : select.children) { - if (child == select.groupBy() || child == select.orderBy() || child == select.having()) - { - bool old_setting = data.settings.prefer_column_name_to_alias; - data.settings.prefer_column_name_to_alias = false; + if (needVisitChild(child)) visit(child, data); - data.settings.prefer_column_name_to_alias = old_setting; - } - else - { - if (needVisitChild(child)) - visit(child, data); - } } /// If the WHERE clause or HAVING consists of a single alias, the reference must be replaced not only in children, diff --git a/tests/queries/0_stateless/01764_prefer_column_name_to_alias.reference b/tests/queries/0_stateless/01764_prefer_column_name_to_alias.reference index 6fde46c38a4..8ee34598a59 100644 --- a/tests/queries/0_stateless/01764_prefer_column_name_to_alias.reference +++ b/tests/queries/0_stateless/01764_prefer_column_name_to_alias.reference @@ -1,3 +1,5 @@ 4.5 9 3 2 3 3 +3 1 1 2 +3 1 1 2 diff --git a/tests/queries/0_stateless/01764_prefer_column_name_to_alias.sql b/tests/queries/0_stateless/01764_prefer_column_name_to_alias.sql index 5524712c3c6..194d2b90854 100644 --- a/tests/queries/0_stateless/01764_prefer_column_name_to_alias.sql +++ b/tests/queries/0_stateless/01764_prefer_column_name_to_alias.sql @@ -6,3 +6,13 @@ set prefer_column_name_to_alias = 1; SELECT avg(number) AS number, max(number) FROM numbers(10); SELECT sum(x) AS x, max(x) FROM (SELECT 1 AS x UNION ALL SELECT 2 AS x) t settings prefer_column_name_to_alias = 1; select sum(C1) as C1, count(C1) as C2 from (select number as C1 from numbers(3)) as ITBL settings prefer_column_name_to_alias = 1; + +DROP TABLE IF EXISTS mytable; +CREATE TABLE IF NOT EXISTS mytable (start_ts UInt32, end_ts UInt32, uuid String) ENGINE = MergeTree() ORDER BY start_ts; +INSERT INTO mytable VALUES (1, 2, 3); + +SELECT any(uuid) AS id, max(end_ts) - any(start_ts) AS time_delta, any(start_ts) AS start_ts, max(end_ts) AS end_ts FROM mytable GROUP BY uuid HAVING max(end_ts) < 1620141001 ORDER BY any(start_ts) DESC; + +SELECT any(uuid) AS id, max(end_ts) - any(start_ts) AS time_delta, any(start_ts) AS start_ts, max(end_ts) AS end_ts FROM mytable GROUP BY uuid HAVING max(end_ts) < 1620141001 ORDER BY any(start_ts) DESC SETTINGS prefer_column_name_to_alias=1; + +DROP TABLE mytable;