Clickhouse其它类型表引擎(Live View、Null、URL)
目录
- 1. Live View表引擎
- 2. Null表引擎
- 3. URL表引擎
1. Live View表引擎
Live View不是表引擎,是一种视图,通过监听一条SQL查询语句的结果,当开启监听时,会得到这条SQL查询的结果,之后每一次这条SQL查询语句的结果有变化时,Live View都会收到结果
- 查询是否开启Live View,如果未开启,我们则开启
clickhouse1 :)
clickhouse1 :) select name, value, type from system.settings where name = 'allow_experimental_live_view';SELECTname,value,type
FROM system.settings
WHERE name = 'allow_experimental_live_view'Query id: 1eda4d1d-884c-4bc7-a4d7-015c008f3f5b┌─name─────────────────────────┬─value─┬─type─┐
│ allow_experimental_live_view │ 0 │ Bool │
└──────────────────────────────┴───────┴──────┘1 rows in set. Elapsed: 0.015 sec. clickhouse1 :)
clickhouse1 :) set allow_experimental_live_view = 1;SET allow_experimental_live_view = 1Query id: e2d6685e-35ef-4f4b-8326-009bb80fb316Ok.0 rows in set. Elapsed: 0.002 sec. clickhouse1 :)
这种开启方式只针对此次连接有效
- 创建一张表origin_table_all,并插入数据,作为Live View的监听目标
clickhouse1 :)
clickhouse1 :) create table origin_table_local on cluster sharding_cluster(
:-] id UInt32,
:-] name String,
:-] city String
:-] ) engine = MergeTree()
:-] order by id
:-] ;CREATE TABLE origin_table_local ON CLUSTER sharding_cluster
(`id` UInt32,`name` String,`city` String
)
ENGINE = MergeTree
ORDER BY idQuery id: 4fd0dac5-cdc8-4589-bbc7-9442bffbe4d4┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse2 │ 9000 │ 0 │ │ 3 │ 0 │
│ clickhouse3 │ 9000 │ 0 │ │ 2 │ 0 │
│ clickhouse1 │ 9000 │ 0 │ │ 1 │ 0 │
│ clickhouse4 │ 9000 │ 0 │ │ 0 │ 0 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘4 rows in set. Elapsed: 0.157 sec. clickhouse1 :)
clickhouse1 :) create table origin_table_all on cluster sharding_cluster as origin_table_local
:-] engine = Distributed(sharding_cluster, default, origin_table_local, id);CREATE TABLE origin_table_all ON CLUSTER sharding_cluster AS origin_table_local
ENGINE = Distributed(sharding_cluster, default, origin_table_local, id)Query id: 42b56a44-9c8a-44e2-a164-95e1297da55b┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse2 │ 9000 │ 0 │ │ 3 │ 0 │
│ clickhouse3 │ 9000 │ 0 │ │ 2 │ 0 │
│ clickhouse1 │ 9000 │ 0 │ │ 1 │ 0 │
│ clickhouse4 │ 9000 │ 0 │ │ 0 │ 0 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘4 rows in set. Elapsed: 0.127 sec. clickhouse1 :)
clickhouse1 :) insert into origin_table_all(id, name, city) values(1, 'name1', 'Beijing');INSERT INTO origin_table_all (id, name, city) VALUESQuery id: e862bf51-c9ab-4a36-a22f-7b1907930f9aOk.1 rows in set. Elapsed: 0.004 sec. clickhouse1 :)
- 创建Live View,并开启监听
clickhouse1 :)
clickhouse1 :) create live view live_view_origin as select count(*) from origin_table_all;CREATE LIVE VIEW live_view_origin AS
SELECT count(*)
FROM origin_table_allQuery id: 8491c2f3-e802-44bc-9295-7355b5e1e66dOk.0 rows in set. Elapsed: 0.007 sec. clickhouse1 :)
clickhouse1 :) watch live_view_origin;WATCH live_view_originQuery id: 1d163536-b6ce-4e4f-8cb2-ae3da0dff4b5┌─count()─┬─_version─┐
│ 1 │ 1 │
└─────────┴──────────┘
→ Progress: 1.00 rows, 16.00 B (7.89 rows/s., 126.25 B/s.)
Live View不支持on cluster cluster name
方式创建
- 开启另外一个client, 并向origin_table_all表插入一条数据
clickhouse1 :)
clickhouse1 :) insert into origin_table_all(id, name, city) values(2, 'name2', 'Shanghai');INSERT INTO origin_table_all (id, name, city) VALUESQuery id: 41bc8daf-3b59-493f-a2d2-fd59ce560300Ok.1 rows in set. Elapsed: 0.018 sec. clickhouse1 :)
查看Live View, 可以看到自动监听到了变化的数据
clickhouse1 :)
clickhouse1 :) watch live_view_origin;WATCH live_view_originQuery id: 1d163536-b6ce-4e4f-8cb2-ae3da0dff4b5┌─count()─┬─_version─┐
│ 1 │ 1 │
└─────────┴──────────┘
┌─count()─┬─_version─┐
│ 2 │ 2 │
└─────────┴──────────┘
↓ Progress: 2.00 rows, 32.00 B (0.01 rows/s., 0.17 B/s.)
- 再向origin_table_all表插入一条数据
clickhouse1 :)
clickhouse1 :) insert into origin_table_all(id, name, city) values(3, 'name3', 'Guangzhou');INSERT INTO origin_table_all (id, name, city) VALUESQuery id: 33db4fc0-aac2-4f1c-b20d-53b4303667b8Ok.1 rows in set. Elapsed: 0.008 sec. clickhouse1 :)
再次查看Live View, 可以看到自动监听到了变化的数据
clickhouse1 :) watch live_view_origin;WATCH live_view_originQuery id: 1d163536-b6ce-4e4f-8cb2-ae3da0dff4b5┌─count()─┬─_version─┐
│ 1 │ 1 │
└─────────┴──────────┘
┌─count()─┬─_version─┐
│ 2 │ 2 │
└─────────┴──────────┘
┌─count()─┬─_version─┐
│ 3 │ 3 │
└─────────┴──────────┘
← Progress: 3.00 rows, 48.00 B (0.01 rows/s., 0.10 B/s.)
2. Null表引擎
将数据insert到Null表引擎,系统不会报错,但是会忽略插入的数据,select的时候也查询不到数据
如果物化视图源表为Null表引擎,物化视图能同步到数据
- 创建Null表和物化视图
clickhouse1 :)
clickhouse1 :) create table null_table_local on cluster sharding_cluster(
:-] id UInt32,
:-] name String,
:-] city String
:-] ) engine = Null;CREATE TABLE null_table_local ON CLUSTER sharding_cluster
(`id` UInt32,`name` String,`city` String
)
ENGINE = NullQuery id: f943303d-3142-4e89-8a50-61154728dd93┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse2 │ 9000 │ 0 │ │ 3 │ 0 │
│ clickhouse3 │ 9000 │ 0 │ │ 2 │ 0 │
│ clickhouse1 │ 9000 │ 0 │ │ 1 │ 0 │
│ clickhouse4 │ 9000 │ 0 │ │ 0 │ 0 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘4 rows in set. Elapsed: 0.146 sec. clickhouse1 :)
clickhouse1 :) create table null_table_all on cluster sharding_cluster as null_table_local
:-] engine = Distributed(sharding_cluster, default, null_table_local, id);CREATE TABLE null_table_all ON CLUSTER sharding_cluster AS null_table_local
ENGINE = Distributed(sharding_cluster, default, null_table_local, id)Query id: c62fdfde-1ba4-4122-bd36-46114731d5e6┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse4 │ 9000 │ 0 │ │ 3 │ 3 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse2 │ 9000 │ 0 │ │ 2 │ 0 │
│ clickhouse3 │ 9000 │ 0 │ │ 1 │ 0 │
│ clickhouse1 │ 9000 │ 0 │ │ 0 │ 0 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘4 rows in set. Elapsed: 0.094 sec. clickhouse1 :)
clickhouse1 :) create table data_table_local on cluster sharding_ha(
:-] id UInt32,
:-] name String,
:-] city String
:-] ) engine = ReplicatedMergeTree('/clickhouse/tables/data_table/{shard}', '{replica}')
:-] order by id;CREATE TABLE data_table_local ON CLUSTER sharding_ha
(`id` UInt32,`name` String,`city` String
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/data_table/{shard}', '{replica}')
ORDER BY idQuery id: 56d6fa19-6407-4738-b30f-936e157e479f┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse3 │ 9000 │ 0 │ │ 3 │ 2 │
│ clickhouse1 │ 9000 │ 0 │ │ 2 │ 2 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
┌─host────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ clickhouse2 │ 9000 │ 0 │ │ 1 │ 0 │
│ clickhouse4 │ 9000 │ 0 │ │ 0 │ 0 │
└─────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘4 rows in set. Elapsed: 0.171 sec. clickhouse1 :)
clickhouse1 :) create materialized view view_table_all
:-] engine = Distributed(sharding_ha, default, data_table_local, id)
:-] as select * from null_table_all;CREATE MATERIALIZED VIEW view_table_all
ENGINE = Distributed(sharding_ha, default, data_table_local, id) AS
SELECT *
FROM null_table_allQuery id: 7612a63a-f0b8-4e16-877a-af7c79293c14Ok.0 rows in set. Elapsed: 0.006 sec. clickhouse1 :)
- 向null_table_all表插入数据
clickhouse1 :) insert into null_table_all(id, name, city) values(1, 'name1', 'Beijing');
clickhouse1 :) insert into null_table_all(id, name, city) values(2, 'name2', 'Shanghai');
clickhouse1 :) insert into null_table_all(id, name, city) values(3, 'name3', 'Guangzhou');
- 查询null_table_all和view_table_all表数据
clickhouse1 :)
clickhouse1 :) select * from null_table_all;SELECT *
FROM null_table_allQuery id: 86652fdd-3307-4283-b2c1-290a6c4dc905Ok.0 rows in set. Elapsed: 0.014 sec. clickhouse1 :)
clickhouse1 :) select * from view_table_all;SELECT *
FROM view_table_allQuery id: 36f47e8d-5b53-4e79-b4f3-b2878fc43290┌─id─┬─name──┬─city─────┐
│ 2 │ name2 │ Shanghai │
└────┴───────┴──────────┘
┌─id─┬─name──┬─city────┐
│ 1 │ name1 │ Beijing │
└────┴───────┴─────────┘
┌─id─┬─name──┬─city──────┐
│ 3 │ name3 │ Guangzhou │
└────┴───────┴───────────┘3 rows in set. Elapsed: 0.024 sec. clickhouse1 :)
3. URL表引擎
todo
Clickhouse其它类型表引擎(Live View、Null、URL)相关推荐
- Clickhouse外部储存表引擎(HDFS、MySQL、JDBC、Kafka、File)
目录 1. HDFS表引擎 1.1 准备工作 1.2 HDFS表负责读写 1.3 HDFS表负责读, 不负责写 2. MySQL表引擎 2.1 表引擎的基本操作 2.2 表引擎配合物化视图 3. JD ...
- clickhouse 的mysql表引擎
mysql表引擎 clickhouse的mysql表引擎可以和远端的mysql数据库表建立联系,这样如果远端的mysql表数据非常大的时候就可以利用clickhouse表引擎的olap能力进行数据查询 ...
- clickhouse的kafka表引擎 +接口表
kafka表引擎 kafka表引擎能订阅kafka的主题消息并实时接收kafka主题数据,目前kafka表引擎支持消息的最少一次的语义,目前常用的使用clickhouse接收并处理kafka消息的方式 ...
- mysql 修改表 引擎,mysql如何修改表类型(表引擎)
参考阅读:http://www.manongjc.com/article/1205.html 最近遇到一个修改 MySQL 表类型的问题,以前在 phpmyadmin 管理 mysql 数据库时,建立 ...
- Clickhouse Distributed分布式表引擎的基本介绍和使用说明
目录 1. 分布式的本地表 1.1 分布式的创建本地表 1.2 分布式的更改本地表表名 1.3 分布式的删除本地表 2. Distributed表 2.1 创建Distributed表 2.2 删除分 ...
- ClickHouse 合并树表引擎 MergeTree 原理分析
目录 前言 MergeTree 存储 MergeTree思想 MergeTree存储结构 MergeTree查询 索引检索 数据Sampling 数据扫描 建表
- 使用clickhouse时mysql表引擎从mysql获取数据时时区自动加八小时[已解决]
今天用clickhouse从mysql中导入数据时忽然发现此问题,之后试验了更改CK时区到上海,更改CK服务器时区到上海,都无济于事. 偶然通过CK命令行查询了一下数据,发现居然时间是对的,才想到应该 ...
- 3、ClickHouse表引擎-MergeTree引擎
ClickHouse系列文章 1.ClickHouse介绍 2.clickhouse安装与简单验证(centos) 3.ClickHouse表引擎-MergeTree引擎 4.clickhouse的L ...
- mysql表引擎修改
1.修改建表引擎 [sql] view plaincopyprint? mysql> CREATE TABLE test_2( -> name varchar(10), -> yea ...
最新文章
- きゃらコレ! -ALICESOFT- 汉化补丁
- Spring Mybatis实例SqlSessionDaoSupport混用xml配置和注解
- 懒加载--初步理解. by:王朋
- 天堂Lineage(單機版)從零開始架設教學 Installing Lineage 3.52 Server - On Windows
- 鼠标手势识别 [Flash]
- vue如何取消下拉框按回车自动下拉_如何用大白菜重装系统|大白菜怎么重装系统教程详解...
- JVM 可设置最大内存
- MySQL服务器状态变量
- 大数据在人力资源管理当中的应用
- 如何在新的Apple TV遥控器上调整触摸灵敏度
- vue功能-数字键盘
- 用gfortran编译C和Fortran
- ORA-12170:TNS:连接超时错误处理
- 【CXY】JAVA基础 之 语法基础
- CollapsingToolbarLayout 标题字体及颜色设置
- 做一个简单网页(做一个简单网页多少钱)
- ISO26262解析(九)——系统部分
- QQ空间视频下载详细教程(手机端)
- J0ker的CISSP之路:How CISSP(2)
- java 进销存C S_java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
热门文章
- 三点运算符(三点语法)
- 节日营销方案:你值得关注的6个策略!
- 排队论,对策论,层次分析法
- 捷报频传!同程艺龙IPO在即,7月份微信小程序排名第二
- C++数组连接求能被7整除的数
- android xlog崩溃日志,Android第三方log库:xlog使用记录
- latex 如何输入 双斜杠 单斜杠
- Centos7 卸载mysql5.7详细步骤,Linux删除Mysql5.7详细操作
- mysql条件删除表中某些行数据_根据MySQL中的条件仅删除表中的某些行
- 【云原生之Docker实战】使用Docker部署Snipe-It固定资产管理平台