1 CREATE TABLE optimized_select_final (t DateTime, x Int32) ENGINE = ReplacingMergeTree() PARTITION BY toYYYYMM(t) ORDER BY x INSERT INTO optimized_select_final SELECT toDate('2000-01-01'), number FROM numbers(1000000) INSERT INTO optimized_select_final SELECT toDate('2020-01-01'), number FROM numbers(1000000) OPTIMIZE TABLE optimized_select_final SELECT * FROM optimized_select_final FINAL DROP TABLE IF EXISTS optimized_select_final