2022-11-04 14:01:38 +00:00
|
|
|
SET allow_experimental_analyzer = 1;
|
2022-11-07 17:48:23 +00:00
|
|
|
SET optimize_syntax_fuse_functions = 1, optimize_fuse_sum_count_avg = 1;
|
2022-11-04 14:01:38 +00:00
|
|
|
|
|
|
|
DROP TABLE IF EXISTS fuse_tbl;
|
|
|
|
|
|
|
|
CREATE TABLE fuse_tbl(a Nullable(Int8), b Int8) Engine = Log;
|
|
|
|
|
|
|
|
INSERT INTO fuse_tbl VALUES (1, 1), (2, 2), (NULL, 3);
|
|
|
|
|
2022-11-07 14:24:27 +00:00
|
|
|
SELECT avg(a), sum(a) FROM (SELECT a FROM fuse_tbl);
|
|
|
|
SELECT avg(a), sum(a) FROM (SELECT a FROM fuse_tbl WHERE isNull(a));
|
|
|
|
SELECT avg(a), sum(a) FROM (SELECT a FROM fuse_tbl WHERE isNotNull(a));
|
|
|
|
|
|
|
|
SELECT avg(b), sum(b) FROM (SELECT b FROM fuse_tbl);
|
2022-11-09 14:33:11 +00:00
|
|
|
SELECT avg(b) * 3, sum(b) + 1 + count(b), count(b) * count(b), count() FROM (SELECT b FROM fuse_tbl);
|
2022-11-07 14:24:27 +00:00
|
|
|
|
2022-11-09 14:33:11 +00:00
|
|
|
SELECT sum(b), count(b) from (SELECT x as b FROM (SELECT sum(b) as x, count(b) FROM fuse_tbl) );
|
2022-11-07 14:24:27 +00:00
|
|
|
|
2022-11-04 14:01:38 +00:00
|
|
|
SELECT sum(a + 1), sum(b), count(b), avg(b), count(a + 1), sum(a + 2), count(a) from fuse_tbl SETTINGS optimize_syntax_fuse_functions = 0;
|
|
|
|
SELECT sum(a + 1), sum(b), count(b), avg(b), count(a + 1), sum(a + 2), count(a) from fuse_tbl;
|
|
|
|
|
2022-11-07 14:24:27 +00:00
|
|
|
EXPLAIN QUERY TREE run_passes = 1 SELECT sum(a), avg(a) from fuse_tbl;
|
|
|
|
EXPLAIN QUERY TREE run_passes = 1 SELECT sum(b), avg(b) from fuse_tbl;
|
2022-11-04 14:01:38 +00:00
|
|
|
EXPLAIN QUERY TREE run_passes = 1 SELECT sum(a + 1), sum(b), count(b), avg(b), count(a + 1), sum(a + 2), count(a) from fuse_tbl;
|
2022-11-07 14:24:27 +00:00
|
|
|
EXPLAIN QUERY TREE run_passes = 1 SELECT avg(b) * 3, sum(b) + 1 + count(b), count(b) * count(b) FROM (SELECT b FROM fuse_tbl);
|
|
|
|
|
2022-11-09 14:33:11 +00:00
|
|
|
EXPLAIN QUERY TREE run_passes = 1 SELECT sum(b), count(b) from (SELECT x as b FROM (SELECT sum(b) as x, count(b) FROM fuse_tbl) );
|
2022-11-04 14:01:38 +00:00
|
|
|
|
|
|
|
SELECT sum(x), count(x), avg(x) FROM (SELECT number :: Decimal32(0) AS x FROM numbers(0)) SETTINGS optimize_syntax_fuse_functions = 0;
|
|
|
|
SELECT sum(x), count(x), avg(x) FROM (SELECT number :: Decimal32(0) AS x FROM numbers(0));
|
|
|
|
|
|
|
|
SELECT sum(x), count(x), avg(x), toTypeName(sum(x)), toTypeName(count(x)), toTypeName(avg(x)) FROM (SELECT number :: Decimal32(0) AS x FROM numbers(10)) SETTINGS optimize_syntax_fuse_functions = 0;
|
|
|
|
SELECT sum(x), count(x), avg(x), toTypeName(sum(x)), toTypeName(count(x)), toTypeName(avg(x)) FROM (SELECT number :: Decimal32(0) AS x FROM numbers(10));
|
|
|
|
|
|
|
|
DROP TABLE fuse_tbl;
|