Skip to content

Commit 84c3fe4

Browse files
committed
refresh ck
1 parent 246754f commit 84c3fe4

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

Database/OLAP/Clickhouse.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ categories:
2020
- 3. [数据库引擎](#数据库引擎)
2121
- 4. [表引擎](#表引擎)
2222
- 4.1. [MergeTree 引擎家族](#mergetree-引擎家族)
23+
- 4.1.1. [Data Replication](#data-replication)
2324
- 4.2. [分布式表引擎 Distributed](#分布式表引擎-distributed)
2425
- 5. [](#表)
2526
- 5.1. [分区表](#分区表)
@@ -28,7 +29,7 @@ categories:
2829
- 7. [Explain](#explain)
2930
- 8. [Tips](#tips)
3031

31-
💠 2024-11-27 13:50:46
32+
💠 2025-07-01 16:50:20
3233
****************************************
3334
# Clickhouse
3435
> [Official Site](https://clickhouse.com)
@@ -162,16 +163,11 @@ categories:
162163
- VersionedCollapsingMergeTree
163164
- GraphiteMergeTree
164165

165-
## 分布式表引擎 Distributed
166-
> [doc: distributed](https://clickhouse.com/docs/en/engines/table-engines/special/distributed)
167166

168-
这种类型的表不会存储数据,可以当作关联表的一层代理,实现并行查询和数据写入的分发.
167+
### Data Replication
168+
复制表引擎能提升查询的性能,但是在写入时,无法保证insert的一致性,*需要等块合并完,才能保证查询的一致性*, 低版本CK会强依赖ZK的性能。
169169

170-
查询Distributed表引擎的过程是: 先查接收请求节点本地的表(和当前节点同分片下的Replication副本节点**不会接收到查询的请求**),对剩余全部分片发送请求(分片中的一个随机副本),然后再聚合各个分片返回的数据,最后返回最终结果。
171-
注意可通过设置不同的cluster来实现是否采用副本节点,如果是未设置副本的节点,每个分片不会有副本冗余。
172-
173-
![](./img/001-dis-send-query.webp)
174-
![](./img/002-dis-merge-result.webp)
170+
> [SharedMergeTree | ClickHouse Docs](https://clickhouse.com/docs/cloud/reference/shared-merge-tree)`Cloud版本有这个引擎做替换,摆脱ZK依赖`
175171
176172
```sql
177173
-- 查看复制表数量
@@ -184,6 +180,15 @@ categories:
184180
select name ,engine, hostname(), metadata_modification_time, total_rows, total_bytes
185181
from clusterAllReplicas('default_cluster', 'system.tables')
186182
where database = 'db' and engine = 'ReplicatedMergeTree';
183+
184+
-- 查看块合并数量,判断表是否最终一致
185+
select count(*) from system.replication_queue where table = 'xxx_local';
186+
187+
-- 查看块合并的情况, 注意shard表写入后的延迟
188+
select hostname() as host,*
189+
from clusterAllReplicas('default_cluster', system.parts)
190+
where database='db_name' and table='xxx_table_local'
191+
order by modification_time desc
187192
```
188193
************************
189194

@@ -192,6 +197,17 @@ categories:
192197
- 写入: 会有部分节点上没有数据,但是全部节点的数据总量是对的
193198
- 查询: 一条SQL每次查询的结果都不一样(各个分片内随机选择副本再合并查询结果而导致的)
194199

200+
## 分布式表引擎 Distributed
201+
> [doc: distributed](https://clickhouse.com/docs/en/engines/table-engines/special/distributed)
202+
203+
这种类型的表不会存储数据,可以当作关联表的一层代理,实现并行查询和数据写入的分发.
204+
205+
查询Distributed表引擎的过程是: 先查接收请求节点本地的表(和当前节点同分片下的Replication副本节点**不会接收到查询的请求**),对剩余全部分片发送请求(分片中的一个随机副本),然后再聚合各个分片返回的数据,最后返回最终结果。
206+
注意可通过设置不同的cluster来实现是否采用副本节点,如果是未设置副本的节点,每个分片不会有副本冗余。
207+
208+
![](./img/001-dis-send-query.webp)
209+
![](./img/002-dis-merge-result.webp)
210+
195211
************************
196212
#
197213
> [doc: create table](https://clickhouse.com/docs/en/sql-reference/statements/create/table)

0 commit comments

Comments
 (0)