在Clickhouse中, 一般的有2种部署方式,3种使用方式:
部署方式:
使用方式:
不同的节点
看到的数据可能是不一样
的。集群化操作
,比如上图中的Sam和Jim
集群化操作时, SQL语句中需要添加 on cluster XXXX
, XXX表示集群名。下面简单介绍集群化操作和单节点操作的基本SQL。
create database db_test on cluster default_cluster
drop database db_test on cluster default_cluster
CREATE TABLE db_test.tbl_replac_merge_test on cluster default_cluster
(
id String,
code String,
create_time DateTime
)
ENGINE = ReplacingMergeTree()
PARTITION BY toYYYYMM(create_time)
PRIMARY KEY id
ORDER BY (id, code);
drop table db_test.tbl_replac_merge_test on cluster default_cluster
create database db_test;
drop database db_test;
CREATE TABLE db_test.tbl_replac_merge_test
(
`id` String,
`code` String,
`create_time` DateTime
)
ENGINE = ReplacingMergeTree()
PARTITION BY toYYYYMM(create_time)
PRIMARY KEY id
ORDER BY (id, code);
drop table db_tetbl_replac_merge_test
CREATE DATABASE db_100 on cluster default_cluster;
CREATE TABLE db_100.tb_1_local on cluster default_cluster
(
`c1` Int64,
`c2` String,
`_sign` Int8,
`_version` UInt64
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/5a165fe5-ab38-4bf2-a6ee-5124a65ed1aa/{shard}', '{replica}', _version)
ORDER BY (c1, c2)
SETTINGS index_granularity = 8192
CREATE TABLE db_100.tb_1 on cluster default_cluster
(
`c1` Int64,
`c2` String,
`_sign` Int8,
`_version` UInt64
)
ENGINE = Distributed('default_cluster', 'db_1', 'tb_1_local', cityHash64(toString((c1, c2))))
更多Clickhouse建表文档:
https://clickhouse.tech/docs/en/sql-reference/statements/create/table/
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。