This commit is contained in:
Amos Bird 2021-05-12 02:30:16 +08:00
parent 4ff612f2c3
commit 62153e7030
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 13 additions and 11 deletions

View File

@ -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,

View File

@ -1,3 +1,5 @@
4.5 9
3 2
3 3
3 1 1 2
3 1 1 2

View File

@ -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;