我正在尝试了解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替换该行。
触发与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 │ └───────┴─────────┴────────┴────────────┴─────────┘
发布于 2017-10-03 23:52:50
从逻辑上讲,它应该如您所描述的那样工作。可能是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
https://stackoverflow.com/questions/46486053
复制相似问题