1
1
CREATE TABLE with_lonely
(
`id` UInt64,
`dt` Date,
`val` UInt64,
`version` UInt64
)
ENGINE = ReplacingMergeTree(version)
PARTITION BY dt
ORDER BY (id);
INSERT INTO with_lonely SELECT number, '2022-10-28', number*10, 0 FROM numbers(3000000);
INSERT INTO with_lonely SELECT number+500000, '2022-10-28', number*10, 1 FROM
numbers(3000000);
OPTIMIZE TABLE with_lonely PARTITION '2022-10-28' FINAL;
INSERT INTO with_lonely SELECT number, '2022-10-29', number*10, 0 FROM numbers(3000000);
INSERT INTO with_lonely SELECT number+500000, '2022-10-29', number*10, 1 FROM
numbers(3000000);
OPTIMIZE TABLE with_lonely PARTITION '2022-10-29' FINAL;
INSERT INTO with_lonely SELECT number, '2022-10-30', number*10, 0 FROM numbers(3000000);
INSERT INTO with_lonely SELECT number+500000, '2022-10-30', number*10, 1 FROM
numbers(3000000);
OPTIMIZE TABLE with_lonely PARTITION '2022-10-30' FINAL;
INSERT INTO with_lonely SELECT number, '2022-10-31', number*10, 0 FROM numbers(3000000);
INSERT INTO with_lonely SELECT number+500000, '2022-10-31', number*10, 1 FROM
numbers(3000000);
OPTIMIZE TABLE with_lonely PARTITION '2022-10-31' FINAL;
INSERT INTO with_lonely SELECT number, '2022-11-01', number*10, 0 FROM numbers(500000);
INSERT INTO with_lonely SELECT number+50000, '2022-11-01', number*10, 1 FROM
numbers(500000);
INSERT INTO with_lonely SELECT number+60000, '2022-11-01', number*10, 2 FROM
numbers(500000);
INSERT INTO with_lonely SELECT number+70000, '2022-11-01', number*10, 3 FROM
numbers(500000);
SELECT max(val), count(*) FROM with_lonely FINAL;
SELECT max(val), count(*) FROM with_lonely FINAL WHERE dt != '2022-11-01';
DROP TABLE IF EXISTS with_lonely;