clickhouse replacingmergetree

watbbzwu  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(1)|浏览(405)

我在试着去了解 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); 正如预期的那样,有两行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) ,我希望此表上的合并将替换id=1的行,该行具有较低版本2。
触发与的合并 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 │ └───────┴─────────┴────────┴────────────┴─────────┘

t2a7ltrp

t2a7ltrp1#

从逻辑上讲,它应该像你描述的那样工作。可能是因为 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

相关问题