create table matview_1
(
a String,
b_count AggregateFunction(uniq, UInt64)
) Engine=MergeTree partition by tuple()
ORDER by a
SETTINGS index_granularity = 1024;
create table matview_10000
(
a String,
b_count AggregateFunction(uniq, String)
) Engine=MergeTree partition by tuple()
ORDER by a
SETTINGS index_granularity = 1024;
DROP TABLE IF EXISTS matview_1
DROP TABLE IF EXISTS matview_10000
INSERT INTO matview_10000
SELECT a, uniqState(b) b_count
FROM
(
SELECT toString(intDiv(number, 20000)) a, toString(number % 10000) b
FROM numbers_mt(20000000)
)
GROUP BY a
SETTINGS max_insert_threads=8;
OPTIMIZE TABLE matview_10000 FINAL
INSERT INTO matview_1
SELECT '1', uniqState(number) b_count
FROM
(
SELECT *
FROM numbers_mt(2000000)
)
GROUP BY number
SETTINGS max_insert_threads=8;
OPTIMIZE TABLE matview_1 FINAL
select a, uniqMerge(b_count) as b_count from matview_10000 prewhere a='55' group by a FORMAT Null SETTINGS max_threads=1;
select uniqMerge(b_count) as b_count from matview_10000 FORMAT Null SETTINGS max_threads=1;
select uniqMerge(b_count) as b_count FROM matview_1 FORMAT Null SETTINGS max_threads=1;