ENGINE - ReplaceMergeTree[ver]
参数:ver,版本列。版本列的类型为UInt*、Date或DateTime。可选参数。
合并的时候,ReplacingTree从所有相同主键的行中选择一行留下:如果ver未指定,选择最后一条。如果制定了ver列,选择ver值最大的版本。
DROP TABLE replacingMergeTreeDemo;
CREATE TABLE replacingMergeTreeDemo
(
UserID UInt32,
CounterID UInt32,
UserName String,
EventDate Date
) ENGINE = ReplacingMergeTree()
ORDER BY (UserID, CounterID)
PRIMARY KEY (UserID);
分三批次插入数据, 为了观察效果, 下面的三段脚本依次按顺序分别执行, 不要一起执行
#批次1:
insert into replacingMergeTreeDemo values(1,100,'xiaohe1','2020-04-21');
insert into replacingMergeTreeDemo values(2,100,'xiaohe2','2020-04-22');
insert into replacingMergeTreeDemo values(3,102,'xiaohe3','2020-04-23');
#批次2:
insert into replacingMergeTreeDemo values(3,103,'xiaohe3','2020-04-23');
insert into replacingMergeTreeDemo values(2,101,'xiaohe2','2020-04-24');
insert into replacingMergeTreeDemo values(1,100,'xiaohe1','2020-04-20');
#批次3:
insert into replacingMergeTreeDemo values(2,100,'xiaohe2','2020-04-23');
select * from replacingMergeTreeDemo;
optimize table replacingMergeTreeDemo;
DROP TABLE replacingMergeTreeDemo;
CREATE TABLE replacingMergeTreeDemo
(
UserID UInt32,
CounterID UInt32,
UserName String,
EventDate Date
) ENGINE = ReplacingMergeTree(EventDate)
ORDER BY (UserID, CounterID)
PRIMARY KEY (UserID);
分三批次插入数据, 为了观察效果, 下面的三段脚本依次按顺序分别执行, 不要一起执行
#批次1:
insert into replacingMergeTreeDemo values(1,100,'xiaohe1','2020-04-21');
insert into replacingMergeTreeDemo values(2,100,'xiaohe2','2020-04-22');
insert into replacingMergeTreeDemo values(3,102,'xiaohe3','2020-04-23');
#批次2:
insert into replacingMergeTreeDemo values(3,103,'xiaohe3','2020-04-23');
insert into replacingMergeTreeDemo values(2,101,'xiaohe2','2020-04-24');
insert into replacingMergeTreeDemo values(1,100,'xiaohe1','2020-04-20');
#批次3:
insert into replacingMergeTreeDemo values(2,100,'xiaohe2','2020-04-23');
select * from replacingMergeTreeDemo;
optimize table replacingMergeTreeDemo;