drop table if exists tp;
create table tp (type Int32, eventcnt UInt64,
projection p (select sum(eventcnt), type group by type))
engine = ReplacingMergeTree order by type;
insert into tp select number%3, 1 from numbers(3);
insert into tp select number%3, 2 from numbers(3);
optimize table tp final;
set allow_experimental_projection_optimization = 0, force_optimize_projection = 0;
select sum(eventcnt) eventcnt, type
from tp
group by type
┌─eventcnt─┬─type─┐
│ 2 │ 0 │
│ 2 │ 2 │
│ 2 │ 1 │
└──────────┴──────┘
set allow_experimental_projection_optimization = 1, force_optimize_projection = 1;
select sum(eventcnt) eventcnt, type
from tp
group by type
┌─eventcnt─┬─type─┐
│ 3 │ 0 │
│ 3 │ 2 │
│ 3 │ 1 │
└──────────┴──────┘