Hive 优化之 共享中间结果集
来源:互联网 发布:教打字的软件 编辑:程序博客网 时间:2024/05/30 23:18
转:http://blog.csdn.net/kwu_ganymede/article/details/49927311
1、优化前的SQL
- SELECT
- COUNT(*) pv
- FROM
- (
- SELECT
- cookieid,
- userid,
- to_date(DATETIME) day1
- FROM
- ods.tracklog_5min
- WHERE
- DAY>='20151001'
- AND DAY<='20151031'
- AND lower(requesturl) IN ('http://chat.hexun.com/',
- 'http://zhibo.hexun.com/'))t1
- INNER JOIN
- (
- SELECT
- cookieid,
- to_date(DATETIME) day2
- FROM
- ods.tracklog_5min
- WHERE
- DAY>='20151001'
- AND DAY<='20151031'
- AND ((
- lower(requesturl) LIKE 'http://zhibo.hexun.com/%'
- OR lower(requesturl) LIKE 'http://chat.hexun.com/%')
- AND requesturl LIKE '%/default.html%'))t2
- ON
- t1.cookieid=t2.cookieid
- AND t1.day1=t2.day2
- INNER JOIN
- (
- SELECT
- cookieid,
- to_date(DATETIME) day3
- FROM
- ods.tracklog_5min
- WHERE
- DAY>='20151001'
- AND DAY<='20151031'
- AND ( (
- lower(requesturl) LIKE 'http://px.hexun.com/%'
- AND lower(requesturl) LIKE '%/default.html%' )
- OR (
- lower(requesturl) LIKE 'http://px.hexun.com/pack/%'
- AND lower(requesturl) LIKE '%.html%' )
- OR (
- lower(requesturl) LIKE 'http://px.hexun.com/p/%'
- AND lower(requesturl) LIKE '%.html%' ) ))t3
- ON
- t1.cookieid=t3.cookieid
- AND t1.day1=t3.day3
- LEFT JOIN
- stage.saleplatform_productvisitdetail_temp t4
- ON
- t1.userid=t4.userid
- WHERE
- t4.createtime>t1.day1
- OR t4.userid IS NULL;
可以看,上面的SQL针对同一源表的数据查询了三次,浪费了系统的资源,相同的源完全可以通用。
2、优化后的SQL
抽出公共数据
- create table default.tracklog_10month as
- select * from ods.tracklog_5min
- WHERE DAY>='20151001' AND DAY<='20151031';
- SELECT
- COUNT(*) pv
- FROM
- (
- SELECT
- cookieid,
- userid,
- to_date(DATETIME) day1
- FROM
- default.tracklog_10month
- WHERE
- lower(requesturl) IN ('http://chat.hexun.com/',
- 'http://zhibo.hexun.com/'))t1
- INNER JOIN
- (
- SELECT
- cookieid,
- to_date(DATETIME) day2
- FROM
- default.tracklog_10month
- WHERE (lower(requesturl) LIKE 'http://zhibo.hexun.com/%'
- OR lower(requesturl) LIKE 'http://chat.hexun.com/%')
- AND requesturl LIKE '%/default.html%')t2
- ON
- t1.cookieid=t2.cookieid
- AND t1.day1=t2.day2
- INNER JOIN
- (
- SELECT
- cookieid,
- to_date(DATETIME) day3
- FROM
- default.tracklog_10month
- WHERE
- ( (
- lower(requesturl) LIKE 'http://px.hexun.com/%'
- AND lower(requesturl) LIKE '%/default.html%' )
- OR (
- lower(requesturl) LIKE 'http://px.hexun.com/pack/%'
- AND lower(requesturl) LIKE '%.html%' )
- OR (
- lower(requesturl) LIKE 'http://px.hexun.com/p/%'
- AND lower(requesturl) LIKE '%.html%' ) ))t3
- ON
- t1.cookieid=t3.cookieid
- AND t1.day1=t3.day3
- LEFT JOIN
- stage.saleplatform_productvisitdetail_temp t4
- ON
- t1.userid=t4.userid
- WHERE
- t4.createtime>t1.day1
- OR t4.userid IS NULL;
3、共享中间结果集
本质就是降IO,减少MR阶段中大量读写磁盘及网络IO的压力。
阅读全文
0 0
- Hive 优化之 共享中间结果集
- hive共享中间结果集
- hive使用技巧(二)——共享中间结果集
- hive中间结果和结果的压缩
- hive 压缩 最终结果 中间结果
- hive结果及中间结果压缩
- 记录一下Hive中间和最终结果压缩
- Hive 之 优化
- Hive之 优化篇
- Hive 之 数据倾斜优化
- Google优化之搜索结果优化篇
- C++中间结果溢出
- 报表性能优化方案之数据集缓存与共享
- hive优化之控制hive任务中的map数
- hive优化之控制hive任务中的reduce数
- [一起学Hive]之十二-Hive SQL的优化
- hive学习之三:项目中的hive优化实践
- [一起学Hive]之十二-Hive SQL的优化
- iOS高级调试&逆向技术-汇编寄存器调用约定教程
- 安卓API指南之Fragment回顾
- Mac OS 10.13.1 brew install opencv log
- 2017秋招总结
- 静态导入
- Hive 优化之 共享中间结果集
- Linux中的system()函数工作原理
- Spark2.2 任务调度机制schedule()源码剖析
- Android 判断有效的Sim card数
- error while loading shared libaries( libc.so.6误删)(开机启动不了)
- 前端之js框架-vue
- TensorFlow学习笔记(八)
- 当面试官问你“我为什么要聘用你”
- Hadoop Shell命令