Clickhouse has special options "do_not_merge_across_partitions_select_final" for ReplaceMergeTree Engine, which allows make fast select on the "optimized" partitions. Unfortunate you have to run manually (crontab)  "OPTIMIZE TABLE ... PARTITION ... FINAL" . 

It will be great to have some options which will tell Clickhouse to compact older partitions on some conditions:

i.e.
```
CREATE TABLE select_final (t DateTime, x Int32, string String) ENGINE = ReplacingMergeTree() PARTITION BY toYYYYMMDD(t) ORDER BY (x, t)  SETTINGS optimize_partition_after = 3600
```
Clickhouse will check if a partition is older than 3600 seconds and has multiple parts and in such condition will do automatically optimization (compaction) 

P.S. we just discussed with @alexey-milovidov about this options :-) 




active_parts = data.getDataPartsVectorForInternalUsage({MergeTreeData::DataPartState::Active}, lock);
            outdated_parts = data.getDataPartsVectorForInternalUsage({MergeTreeData::DataPartState::Outdated}, lock);
        }
        ActiveDataPartSet active_parts_set{data.format_version};
        for (const auto & part : active_parts)
            active_parts_set.add(part->name);
        for (const auto & part : outdated_parts)
        {
            
            
            
            if (part->version.creation_csn == Tx::RolledBackCSN)
                continue;
            
            
            
            if (part->version.removal_csn != Tx::UnknownCSN)
                continue;
            active_parts_set.add(part->name);
        }
        
        auto remove_pred = [&](const MergeTreeData::DataPartPtr & part) -> bool
        {
            return active_parts_set.getContainingPart(part->info) != part->name;
        };
        std::erase_if(active_parts, remove_pred);
        std::erase_if(outdated_parts, remove_pred);
        std::merge(active_parts.begin(), active_parts.end(),
                   outdated_parts.begin(), outdated_parts.end(),
                   std::back_inserter(data_parts), MergeTreeData::LessDataPart());