带分区的MergeTree
drop table if exists detail_table;
create table if not exists detail_table
(
id UInt8,
ctime DateTime,
money UInt64
)
engine = MergeTree() PARTITION BY toDate(ctime)
ORDER BY id
SETTINGS index_granularity = 8192;
INSERT INTO default.detail_table (id, ctime, money) VALUES (1, '2021-08-06 13:12:13', 100);
INSERT INTO default.detail_table (id, ctime, money) VALUES (1, '2021-08-06 13:33:42', 100);
INSERT INTO default.detail_table (id, ctime, money) VALUES (2, '2021-08-07 13:12:17', 200);
INSERT INTO default.detail_table (id, ctime, money) VALUES (2, '2021-08-07 13:33:48', 200);
select * from detail_table;
optimize table detail_table final;
带分区的ReplacingMergeTree
create table if not exists detail_table_copy
(
id UInt8,
ctime DateTime,
money UInt64
)
engine = ReplacingMergeTree(ctime) PARTITION BY toDate(ctime)
ORDER BY id
SETTINGS index_granularity = 8192;
INSERT INTO default.detail_table_copy (id, ctime, money) VALUES (1, '2021-08-06 13:12:13', 100);
INSERT INTO default.detail_table_copy (id, ctime, money) VALUES (1, '2021-08-06 13:33:42', 100);
INSERT INTO default.detail_table_copy (id, ctime, money) VALUES (2, '2021-08-07 13:12:17', 200);
INSERT INTO default.detail_table_copy (id, ctime, money) VALUES (2, '2021-08-07 13:33:48', 200);
select * from detail_table_copy;
optimize table detail_table_copy final;