美文网首页
HIVE SQL 优化

HIVE SQL 优化

作者: 本凡_大数据_机器学习 | 来源:发表于2019-04-15 19:21 被阅读0次

1、reduce 的个数:先看一下跑hive时出现的参数:

in order to change the average load for a reducer (in bytes):

  set hive.exec.reducers.bytes.per.reducer=<number>

(1)、可以设定number的大小来调整reduce个数;每当数据量大于number时就会多产生一个reduce

(2)、In order to limit the maximum number of reducers:

              set hive.exec.reducers.max=<number>

指定reducer的最大个数,如果同时指定了 set hive.exec.reducers.bytes.per.reducer = <number>,

set hive.exec.reducers.max = <number> 的优先级大,会覆盖上面那个参数

(3)、In order to set a constant number of reducers:

              set mapreduce.job.reduces=<number>

指定 set mapreduce.job.reduces = <number>指定reduce的个数,这个参数的优先级大于以上两个

2、where 条件使得 group by 冗余

在写代码时,where已经限定了条件,此时不需要group by ,加上会增加运行的负担(group by 会进行分区,会运行多个reduce,增加不必要的损耗)

3、只有一个reduce情况

(1)、没有group by :即使设置了reduce的个数也不会变;

(2)、order by:全局排序只产生一个reduce

(3)、笛卡尔积:单纯的两个表join时(没有 on 条件)会发生笛卡尔积,此时只有一个reduce

4、map join :

select /*+ MAPJOIN(a) +*/  a.product_id,b.aisle from  a join b on xxx

map join的使用条件;

(1)、当发生小表 join 大表时,可以mapjoin(小表)将小表存入内存中,在map端join(0.7之前需要加

/*+ MAPJOIN(a) +*/ ,0.7之后由参数hive.auto.convert.join=true控制);小表的阈值:

set hive.mapjoin.smalltable.filesize = 25000000 (25M) 

设置可以使用多大的内存来存储数据(默认为内存的0.55):

set hive.mapjoin.followby.gby.localtask.max.memory.usage = 0.55

(2)、当两个表不等值连接时,也经常使用mapjoin

5、union all / distinct == union

union all 与 union 用于将多个select查询语句结果合并到一个结果里(union 将查询到的结果去重)

union all 不会去重,但在查询时加上distinct有同样的效果。

因为union要进行重复值扫描,所以效率比 union all/distinct 低。

6、数据倾斜

set hive.groupby.skewindata = true

当出现数据倾斜时,设置hive.groupby.skewindata = true 可将一个mapreduce任务拆分成两个

使用情景:凌晨定时任务,需要报表;洗出来的基本表

7、MR 的数量

1个MR:

select

ord.order_id order_id,

tra.product_id product_id,

pri.reordered reordered

from orders ord

join trains tra on a.xx=b.xx

join priors pri on a.xx=c.xx

2个MR

select

ord.order_id,

tra.product_id,

pro.aisle_id

from orders ord

join trains tra on a.xx=b.xx

join products pro on b.xx=c.xx

/*+ STREAMTABLE(a) */ 指定一个大表

8、设置mapreduce是同步执行还是异步执行

set hive.exec.parallel=true

(1)、同步执行:map执行完再执行reduce

(2)、异步执行:map和reduce一起执行

9、怎么定位哪几个key发生倾斜:

可以使用分桶:bucket然后sample抽样

相关文章

  • Hive优化

    Hive数据倾斜优化总结 Hive数据倾斜优化分为配置优化和SQL优化 优先原则: 数据不怕多,避免倾斜。 减少J...

  • 2018-08-05--08-11

    08-05配置1、sql语句练习。根据月乔的文档&sql优化,根据文档练习2、hive语句1)hive,sql连接...

  • Hive优化实践1-数据倾斜及join无关的优化

    Hive SQL的各种优化方法基本 都和数据倾斜密切相关。 Hive的优化分为join相关的优化和join无关的优...

  • 大数据开发之Hive优化篇8-Hive Job优化

    备注:Hive 版本 2.1.1 Hive job优化概述 实际开发过程中,经常会遇到hive sql运行比较慢的...

  • hive积累大全

    此篇内容:hive自定义函数UDF、UDTF,压缩存储方式,hive优化、hive实际编程SQL中的if表达式用法...

  • Hive优化

    核心思想:把Hive SQL 当做Mapreduce程序去优化 注意:以下SQL不会转为Mapreduce来执行,...

  • 25Hive优化(Hive7)(这节很重要)

    本节所讲优化策略适用于任何场景 1.核心思想 把Hive SQL 当做Mapreduce程序去优化以下SQL不会转...

  • HIVE SQL 优化

    1、reduce的个数:先看一下跑hive时出现的参数: in order to change the avera...

  • 面试必备技能-HiveSQL优化

    Hive SQL基本上适用大数据领域离线数据处理的大部分场景。Hive SQL的优化也是我们必须掌握的技能,而且,...

  • hive sql优化实例

    Hive中SQL的优化技巧,核心思想是避免数据倾斜。 1、避免在同一个查询中同时出现count, distinct...

网友评论

      本文标题:HIVE SQL 优化

      本文链接:https://www.haomeiwen.com/subject/attpwqtx.html