【问题标题】:ClickHouse ReplacingMergeTreeClickHouse 替换 MergeTree
【发布时间】:2018-03-11 04:41:18
【问题描述】:

我试图了解ReplacingMergeTree 引擎的工作原理。

我在下表中配置了这样的引擎。

┌─brand─┬─country─┬─id─────┬────updated─┬─version─┐ │ IM │ FR │ 1 │ 2017-09-29 │ 2 │ │ IM │ FR │ 2 │ 2017-09-29 │ 0 │ │ IM │ FR │ 3 │ 2017-09-29 │ 1 │ └───────┴─────────┴────────┴────────────┴─────────┘

此时一切正常。

然后我执行下面的INSERT

INSERT INTO table(brand, country, id, updated, version) VALUES ('IM', 'FR', 1, '2017-10-29', 3);

正如预期的那样,有 2 行 id 为 1

┌─brand─┬─country─┬─id─────┬────updated─┬─version─┐ │ IM │ FR │ 1 │ 2017-09-29 │ 2 │ │ IM │ FR │ 2 │ 2017-09-29 │ 0 │ │ IM │ FR │ 3 │ 2017-09-29 │ 1 │ └───────┴─────────┴────────┴────────────┴─────────┘ ┌─brand─┬─country─┬─id─────┬────updated─┬─version─┐ │ IM │ FR │ 1 │ 2017-10-29 │ 3 │ └───────┴─────────┴────────┴────────────┴─────────┘

由于此表的主键是(brand, country, id),我希望此表上的合并将替换具有较低版本 2 的 id=1 的行。

触发与OPTIMIZE TABLE table 的合并来检查,似乎它并没有以这种方式工作,并且两行都被保留了。

┌─brand─┬─country─┬─id─────┬────updated─┬─version─┐ │ IM │ FR │ 1 │ 2017-10-29 │ 3 │ └───────┴─────────┴────────┴────────────┴─────────┘ ┌─brand─┬─country─┬─id─────┬────updated─┬─version─┐ │ IM │ FR │ 1 │ 2017-09-29 │ 2 │ │ IM │ FR │ 2 │ 2017-09-29 │ 0 │ │ IM │ FR │ 3 │ 2017-09-29 │ 1 │ └───────┴─────────┴────────┴────────────┴─────────┘

【问题讨论】:

  • 你能试试这个OPTIMIZE TABLE table FINAL吗?另外,请向我们展示 create table 语句。
  • 排序键用于去重。如何定义主键无关紧要。确保您按(品牌、国家、ID)订购。

标签: clickhouse


【解决方案1】:

从逻辑上讲,它应该按照您的描述工作。 version 列名可能有问题?如果在表定义时不指定,则称为_part_index?

你能提供你的show create table吗?

有ReplacingMergeTree https://github.com/yandex/ClickHouse/blob/012c5f1079e7a2605e872eb223b9c5dcd065880e/dbms/tests/queries/0_stateless/00325_replacing_merge_tree.sql.disabled的测试

文档:https://clickhouse.yandex/docs/en/table_engines/replacingmergetree.html

【讨论】:

  • 不,它被称为version 一个无符号整数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-09
  • 2019-05-14
  • 2021-10-15
  • 2019-09-22
  • 2020-09-20
  • 1970-01-01
  • 2020-09-25
相关资源
最近更新 更多