CLICKHOUSE学习之:分布式建表

CLICKHOUSE学习之:分布式建表

声明:

此篇文章涉及到一下操作:clickhouse的分布式 建表规则以及,删表语句等
本篇文章的clickhouse部署在4台机器上,所以建表需要在4台机器上创建相同的物理表,而一台机上上有逻辑库,所以还需要多建一张逻辑库对应物理库的表。逻辑表内存储的是表结构,用于快速查询,实际数据存储在4台不同机器的物理表中。

本篇文章仅介绍物理表以及逻辑表的创建规则及语句。涉及少部分其他语句在一下内容中显示

建表规则

1、首先创建物理表,准备好建表语句

声明clickhouse不是只能创建string字符串字段,int对应 iInt64    数值对应Float64

 CREATE TABLE 库名.表名_physical (
  fr String
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = MergeTree() 
PARTITION BY ad_account_id ORDER BY (fr, ad_account_id, category) SETTINGS index_granularity = 8192

ENGINE = MergeTree() ,SETTINGS index_granularity = 8192 是固定的
PARTITION BY 分区字段    
ORDER BY (所有维度字段)

2、首先创建逻辑表,准备好建表语句

CREATE TABLE 逻辑库名.表名(
  fr String,
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = Distributed(mkt_ck_test, 物理库名, 对应的物理表名, cityHash64(fr)) 

ENGINE = Distributed(mkt_ck_test, 物理库名, 对应的物理表名, cityHash64(fr)) 规则固定

 

示例:
 

CREATE TABLE marketing_physical.fem_baidu_account_physical (
  fr String,
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = MergeTree() 
PARTITION BY ad_account_id ORDER BY (fr, ad_account_id, category) SETTINGS index_granularity = 8192

逻辑板建表语句:
CREATE TABLE marketing.fem_baidu_account (
  fr String,
  ad_account_id String,
  ad_account_name String,
  balance String,
  budget String,
  user_stat String,
  user_stat_desc String,
  valid_flows String,
  valid_flows_desc String,
  category String,
  is_deleted String,
  create_time String
) ENGINE = Distributed(mkt_ck_test, marketing_physical, fem_baidu_account_physical, cityHash64(fr)) 

 

分别在不同的机器逻辑库以及物理库中创建重复上述的建表语句即可

clickhoues的命令行操作与mysql语句基本一致一下是几个常用的命令

1.show databases;//查看数据库
2.use 库名;//使用数据库
3.show tables;//展示数据库所有表
4.show create table 表名 ;//查看表的建表语句
5.DROP TABLE 表名;//删除此表

以上结束

感谢观看

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值