ClickHouse Merge引擎表
1、Merge表介绍
Merge表是ClickHouse 的特殊引擎中的一种,Merge表并非MergeTree表,两表没有关联
Merge表不能用来存储数据,只能用于读取数据,可以从任意多张表进行数据关联读取,多个表的读取并行进行,而且源表带有索引,也会生效
2、建表语句
CREATE TABLE ... Engine=Merge(db_name, tables_regexp)
3、参数说明
(1)db_name:已有库名称、ck自带函数表达式、正则表达式
(2)tables_regexp:正则表达式
4、使用示例
CREATE TABLE merge_old(date Date, UserId Int64, EventType String, Cnt UInt64)
ENGINE=MergeTree() PARTITION BY date ORDER BY (UserId, EventType);
INSERT INTO merge_old VALUES ('2018-01-01', 1, 'hit', 3);
CREATE TABLE merge_new(date Date, UserId Int64, EventType String, Cnt UInt64)
ENGINE=MergeTree PARTITION BY date ORDER BY (UserId, EventType) SETTINGS index_granularity=8192;
INSERT INTO merge_new VALUES ('2018-01-02', 2, 'hit', 3);
创建Merge引擎表关联两张旧表
CREATE TABLE merge as merge_old ENGINE=Merge(currentDatabase(), '^merge');
还可以根据虚拟列**_table**查询数据具体属于哪张表