使用 ReplacingMergeTree 作为 updatable table: 如何删除?

Using ReplacingMergeTree as an updatable table: how to delete?

我将 ClickHouse 用于 "kind of updatable large (hundreds millions rows) table" 和 ReplacingMergeTree。我需要批量更新插入并做一些非聚合 [​​=37=]。它工作正常。

即使它有点 hack,而且远非最佳(我的意思是不像 OLAP 的 Clickhouse),它可以很好地扩展并且仍然比或多或少专用于此的系统(例如 HBase 或 RDBM)执行得更快(对于我的需求)。

我使用 ReplacingMergeTree table 和一个键:

CREATE TABLE Things (Key Int32, ValueA Int32, ValueB Int32) 
ENGINE = ReplacingMergeTree() ORDER BY Key

我更新为:

INSERT INTO Things (Key,ValueA,ValueB) ...

和 select 加上“FINAL”修饰符:

SELECT Key,ValueA,ValueB FROM Things FINAL WHERE ...

我可以使用名为 "Killed" 的列来 "delete" 个对象。但有时,我需要清理 "Killed" 个对象以防止 table 无限增长。

我找到的唯一方法是重新创建一个新的 table 并在其中插入非终止行。 有没有更聪明的方法?

ClickHouse 在最近的版本中支持 DML 操作,因此您不需要 ReplacingMergeTree 像这样的 tombstone 记录。

查看 https://clickhouse.yandex/docs/en/query_language/alter/#mutations 了解更多详情。