带分区的MergeTree和ReplacingMergeTree

带分区的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;

猜你喜欢

转载自blog.csdn.net/qq_41081716/article/details/130127040