本文介绍了如何在ClickHouse中创建主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实在文档中发现了几个示例,这些示例通过将参数传递给ENGINE部分来创建主键。
但是我没有找到关于ENGINE的任何参数的说明,它的含义以及如何创建主键。
预先感谢。将此信息添加到不存在的文档中将非常有用。

I did found few examples in the documentation where primary keys are created by passing parameters to ENGINE section.But I did not found any description about any argument to ENGINE, what it means and how do I create a primary key.Thanks in advance. It would be great to add this info to the documentation it it's not present.

推荐答案

MergeTree存储引擎家族支持主键。

Primary key is supported for MergeTree storage engines family.https://clickhouse.tech/docs/en/engines/table_engines/mergetree_family/mergetree/

它被指定为存储引擎的参数。

It is specified as parameters to storage engine.

不支持采样的示例:


MergeTree(EventDate, (CounterID, EventDate), 8192)



MergeTree(EventDate, intHash32(UserID), (CounterID, EventDate, intHash32(UserID)), 8192)

所以, (CounterID,EventDate)(CounterID,EventDate,intHash32(UserID))是这些示例中的主键。

So, (CounterID, EventDate) or (CounterID, EventDate, intHash32(UserID)) is primary key in these examples.

使用ReplicatedMergeTree时,还有两个附加参数,用于标识分片和副本。

When using ReplicatedMergeTree, there are also two additional parameters, identifying shard and replica.

主键是在创建表时指定的,以后不能更改。

Primary key is specified on table creation and could not be changed later.

尽管名称,主键也不是唯一的。它只是定义数据的排序顺序以最佳方式处理范围查询。您可以在表中插入许多具有相同主键值的行。

Despite the name, primary key is not unique. It just defines sort order of data to process range queries in optimal way. You could insert many rows with same value of primary key to a table.

这篇关于如何在ClickHouse中创建主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 07:17