clickhouse 有分片的方法吗?

박배선*_*박배선 1 clickhouse

我有两个关于如何在 clickhouse 中进行分片的问题。

Q1. clickhouse有必要使用分布式引擎进行分片吗?

Q2。我想知道是否可以根据我设置的标准进行分片,而不是根据分片的权重自动分配。

Example.
 - If id is 1, it is stored in shard1.
 - If id is 2, it is stored in shard2.
 - If id is 3, it is stored in shard3.



I understand the sharding through the distribution engine as follows.
- distributed engine use the cluster defined in the config.xml file.
- It is automatically distributed to the shard according to the weight of the shard.
Run Code Online (Sandbox Code Playgroud)

感谢您阅读我的问题。我期待你的回复。

小智 5

Q1. clickhouse有必要使用分布式引擎进行分片吗?

是的。分布式引擎知道如何将查询分发到分布在分片和副本上的本地表。如果没有这个,您将需要在每个分片上运行查询并自行组装结果。

Q2。我想知道是否可以根据我设置的标准进行分片,而不是根据分片的权重自动分配。

是的。有两种方法可以将数据写入分片。

  1. 通过分布式表插入。ClickHouse 将使用分片键分发到本地表。
  2. 直接写入本地表。在这种情况下,由您决定如何分发数据。许多安装都使用这种方法,因为它可以通过直接访问基础表来实现更高的性能。

分布式引擎实际上只是通往本地表的网关,这就是#2 起作用的原因。