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(5000000)
INSERT INTO optimized_select_final SELECT toDate('2020-01-01'), number FROM numbers(5000000)
INSERT INTO optimized_select_final SELECT toDate('2021-01-01'), number FROM numbers(5000000)
INSERT INTO optimized_select_final SELECT toDate('2022-01-01'), number FROM numbers(5000000)
OPTIMIZE TABLE optimized_select_final
SELECT * FROM optimized_select_final FINAL FORMAT Null
DROP TABLE IF EXISTS optimized_select_final