Optimize does not guarantee collapsing or replacing and does not work across partitions (because merge process works only with one partition).
"from final"
is exactly the opposite, guaranteeing the proper result including across partitions but works very slow.
create table test.testcp (p date, v Int32, sign Int8) Engine = CollapsingMergeTree(p, v, 8192, sign)
insert into test.testcp values ('2018-05-16', 33, 1);
insert into test.testcp values ('2018-05-01', 33, -1);
insert into test.testcp values ('2018-04-16', 34, 1);
insert into test.testcp values ('2018-05-16', 34, -1);
optimize table test.testcp partition 201805 final;
optimize table test.testcp partition 201804 final;
select * from test.testcp
2018-05-16 34 -1 <----- 201805 partition
2018-04-16 34 1 <------ 201804 partition
As far as I know for better performance sum(sign) evaluations are recommended
https://clickhouse.yandex/docs/en/table_engines/collapsingmergetree/...write 'sum(Sign)' instead of 'count()'. To calculate the sum of something, write 'sum(Sign * x)' instead of 'sum(x)', and so on....