Remove filter column from HAVING when it is not needed.

This commit is contained in:
Nikolai Kochetov 2021-09-28 12:46:34 +03:00
parent 841ef13dee
commit 09cd955aa6
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
drop table if exists test;
-- #29010
CREATE TABLE test
(
d DateTime,
a String,
b UInt64
)
ENGINE = MergeTree
PARTITION BY toDate(d)
ORDER BY d;
SELECT *
FROM (
SELECT
a,
max((d, b)).2 AS value
FROM test
GROUP BY rollup(a)
)
WHERE a <> '';
-- the same query, but after syntax optimization
SELECT
a,
value
FROM
(
SELECT
a,
max((d, b)).2 AS value
FROM test
GROUP BY a
WITH ROLLUP
HAVING a != ''
)
WHERE a != '';
drop table if exists test;