【大数据技巧】MaxCompute优化去重计算的性能
2017-03-15 10:59
866 查看
免费开通大数据服务:https://www.aliyun.com/product/odps
转载自dachuan
随着双十一数据量的暴增,之前用distinct去重可以简单处理的场景,现在消耗的时间成倍增长。如果用了multiple distinct,那就更要警惕,因为多重去重本身会带来数据量的成倍增长,很可能10分钟的任务,在双十一期间会跑上几个小时都没有结果。
这里介绍一个小技巧,其实在稳定性手册里面已经有过介绍,不过总感觉没有看懂。最近正好做了一次优化,于是在这里小结一下:
例如原来的代码是这样:
那么优化方案可以是这样:
多重去重的优化也可以采用上面的方案,只是要注意Group By的Key是以源表聚合维度为基础,根据distinct计算的值进行组合。
例如下面的这个例子:
那么优化方案可以是:
欢迎加入MaxCompute钉钉群讨论
原文链接:
转载自dachuan
随着双十一数据量的暴增,之前用distinct去重可以简单处理的场景,现在消耗的时间成倍增长。如果用了multiple distinct,那就更要警惕,因为多重去重本身会带来数据量的成倍增长,很可能10分钟的任务,在双十一期间会跑上几个小时都没有结果。
这里介绍一个小技巧,其实在稳定性手册里面已经有过介绍,不过总感觉没有看懂。最近正好做了一次优化,于是在这里小结一下:
例如原来的代码是这样:
select D1,D2, count(distinct case when A is not null then B end) as B_distinct_cnt from xxx group by D1,D2
那么优化方案可以是这样:
create table tmp1 as select D1,D2,B, count( case when A is not null then B end ) as B_cnt from xxx group by D1, D1, B select D1,D2, sum(case when B_cnt > 0 then 1 else 0 end) as B_distinct_cnt from tmp1 group by D1,D2
多重去重的优化也可以采用上面的方案,只是要注意Group By的Key是以源表聚合维度为基础,根据distinct计算的值进行组合。
例如下面的这个例子:
select D1,D2, count(distinct case when A is not null then B end) as B_distinct_cnt , count(distinct case when E is not null then C end) as C_distinct_cnt from xxx group by D1,D2
那么优化方案可以是:
create table tmp1 as select D1,D2,B, count( case when A is not null then B end ) as B_cnt from xxx group by D1, D1, B create table tmp1_1 as select D1,D2, sum(case when B_cnt > 0 then 1 else 0 end) as B_distinct_cnt from tmp1 group by D1,D2 create table tmp2 as select D1,D2,C, count( case when E is not null then C end ) as C_cnt from xxx group by D1, D1, C create table tmp2_1 as select D1,D2, sum(case when C_cnt > 0 then 1 else 0 end) as C_distinct_cnt from tmp1 group by D1,D2 select t1.D1,t1.D2, t1.B_distinct_cnt, t2.C_distinct_cnt from tmp1_1 t1 left outer join tmp2_1 t2 on t1.D1=t2.D1 and t1.D2=t2.D2
欢迎加入MaxCompute钉钉群讨论
原文链接:
http://click.aliyun.com/m/13956/ |
相关文章推荐
- 【大数据技巧】MaxCompute优化去重计算的性能
- 【大数据技巧】MaxCompute优化去重计算的性能
- php导入大量数据到mysql性能优化技巧
- php导入大量数据到mysql性能优化技巧
- HBase性能优化方法总结(四):数据计算
- 【PDF下载】大数据峰会之MaxCompute 2.0 性能优化揭秘
- FPGA计算性能优化-数据运行优化2
- HBase性能优化方法总结(四):数据计算
- 大数据IMF传奇行动绝密课程第116课:Spark Streaming性能优化:如何在毫秒内处理大吞吐量和数据波动比较大的流计算
- MySQL单表百万数据记录分页性能优化技巧
- 提高性能 MSSQL百万数据量 值得注意的30条优化技巧
- Spark商业案例与性能调优实战100课》第3课:商业案例之通过RDD分析大数据电影点评系各种类型的最喜爱电影TopN及性能优化技巧
- HBase性能优化方法总结(四):数据计算
- mysql 超大数据/表管理技巧&MySQL 性能优化的最佳20多条经验
- FPGA计算性能优化--数据运行优化1
- MySQL单表百万数据记录分页性能优化技巧
- php导入大量数据到mysql性能优化技巧
- 大数据IMF传奇行动绝密课程第118课:Spark Streaming性能优化:如何获得和持续使用足够的集群计算资源
- HBase性能优化方法总结(四):数据计算
- Java 性能优化技巧集锦 (3)