ck随笔

1. 分片是逻辑概念, 具体数据都在副本中. (同1分片中的多个副本, 数据完全相同, 以此实现的高可用)
2. 通过Distributed视图才能实现数据分片.
3. 一般来说不同的分片数据会落在不同的机器上, 这样才有意义.
创建replace表(相比replacedMergeTree,它支持集群内合并)
create table falcon0328.relationship_agg_result_local on cluster falcon0328
(
relacode String,
accountfrom SimpleAggregateFunction(any,String),
fromtype SimpleAggregateFunction(any,Int32),
accountto SimpleAggregateFunction(any,String),
totype SimpleAggregateFunction(any,Int32),
relatype SimpleAggregateFunction(any,Int32),
endtime SimpleAggregateFunction(max,Int64),
`count` SimpleAggregateFunction(sum,Int64)
)
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/relationship_agg_result_local','{replica}')
ORDER BY (accountfrom,fromtype,relacode);
#分布式表
CREATE TABLE falcon0328.relationship_agg_result on cluster falcon0328 AS falcon0328.relationship_agg_result_local ENGINE = Distributed(falcon0328, falcon0328, relationship_agg_result_local, rand());
#创建物化视图
create materialized view if not exists falcon0328.relationship_agg_result_view_local on cluster falcon0328
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/relationship_agg_result_view_local','{replica}')
ORDER BY (accountto,totype,relatype)
as select relacode,accountfrom,fromtype,accountto,totype,relatype,endtime,`count`
from falcon0328.relationship_agg_result_local;

浙公网安备 33010602011771号