hive 之with as 和create view 和create temporary table用法
create temporary table test.cc_tmp as select * from test.cc_join where name like '%c%';
explain
select * from test.cc_tmp where id >0
union all
select * from test.cc_tmp where id is null ;
create view test.cc_tmp_v as select * from test.cc_join where name like '%c%'
explain
select * from test.cc_tmp_v where id >0
union all
select * from test.cc_tmp_v where id is null ;
explain with tmp as
(select * from test.cc_join where name like '%c%')select * from tmp where id >0
union all
select * from tmp where id is null
三者
create temporary table 是创建一张临时表,退出当前会话,数据就不见了
通过show create table 可以看到是放在tmp目录的。
create view 其实和with tmp as 很相似,都是把复杂的可以重用的sql简化,我觉得唯一的区别就是 view是可以创建下次再使用的 但是with只是当前sql有效,甚至不是会话有效。
——————————————————————————————————————————
之前网上不知道看的那篇文章说with里面的内容可以复用,也就是只计算一次 下次就不计算了,直接拿上次的结果。放屁。
贴上 view 和with的explain 可以看到 都是经过了两次计算
而create temporary才是真正的一次计算
突然觉得这个例子不好。换个例子
create temporary table test.cc_tmp as select a.id,b.name from test.cc_join a join test.cc_join b on a.id =b.id
select * from test.cc_tmp
union all
select * from test.cc_tmp
create view test.cc_tmp_v as select a.id,b.name from test.cc_join a join test.cc_join b on a.id =b.id
explain
select * from test.cc_tmp_v
union all
select * from test.cc_tmp_v
with tmp as
(
select a.id,b.name from test.cc_join a join test.cc_join b on a.id =b.id)
select * from tmp
union all
select * from tmp
可以看到 这个join with as 和 view 都是执行了两次,但是temporary table 只执行了一次join,所以如果以后尽量不要用with as 卵用没有。
使用temporary table 感觉才是优解
相关文章
- 【WP 8.1开发】How to 图像处理
- 【WP 8.1开发】如何动态生成Gif动画
- 各种癌症都有自己的细分亚型(数据挖掘可以更进一步)
- 【流计算 Oceanus】巧用 Flink 实现高性能 ClickHouse 实时数仓
- 新浪微博SDK开发(2):上传图片的技术难点
- iapp对接云函数上传图片
- 实战MEF(5):导出元数据
- ChebLieNet:不变谱图NN通过李群上的黎曼几何变成了等值的
- 【技术种草】我用 1个肉夹馍的钱,搭了整套大数据系统
- 留存和流失指标
- 从NLP视角看电视剧《狂飙》,会有什么发现?
- 现在的00后,实在是太卷了
- 从开普勒到牛顿:可解释的人工智能在科学发现中的作用(CS)
- 【传感器融合】开源 | 恶劣天气(大雾)中的深度多模态传感器融合
- Mysql字段中包含某个字符时截取后面内容
- Docker 安装mysql数据库
- Mysql 拼接json
- SpringBoot集成ES
- springboot整合MongoDB
- mysql 清理 relay log 和 bin log(1)