本文共 2436 字,大约阅读时间需要 8 分钟。
Hive对于表的操作大部分都是转换为MR作业的形式,为了提高OLAP[online analysis process 在线分析处理]的效率,Hive自身给出了很多的优化策略。
通过explain命令,可以查看Hive语句的操作情况,是否为慢查询,是否走索引,一目了然
explain select sum(...) from table_name;
hive.exec.dynamic.partition.mode = strict // 默认是strict
bucket表
索引
文件格式优化
TEXTFILE, SEQUENCEFILE, RCFILE[可切分], ORC[增强的RCFILE], 和 PARQUET压缩
SET hive.exec.compress.intermediate=true // 设置MR中间数据可以进行压缩,默认是falseSET hive.intermediate.compression.codec=org.apache.hadoop.io.compress.SnappyCodec // 设置MR中间数据压缩算法SET hive.exec.compress.output=true // 设置MR输出数据可以进行压缩,默认是falseSET mapreduce.map.output.compress.codec=org.apache.hadoop.io.compress.SnappyCodec // 设置MR输出数据压缩算法,Hadoop的配置
适用于小数据情况
hive.exec.mode.local.auto = true // 默认falsemapreduce.framework.name = local
运行本地模式的job需要满足的条件
job的输入总大小要小于hive.exec.mode.local.auto.inputbytes.max // 默认是134217728 map任务的数量要小于hive.exec.mode.local.auto.input.files.max // 默认是4 reduce任务的数量要是1或者是0 8. JVM重用SET mapreduce.job.jvm.numtasks=5; // 每个JVM能运行的任务数,默认是1,即为每一个任务开一个JVM,如果设为-1,则没有限制
如果Job之间没有依赖,可以并行执行
hive.exec.parallel = true // 默认是falseSET hive.exec.parallel.thread.number=16 // 默认是8,能够并行执行的job数
select * from ... limit 1,2hive.limit.optimize.enable = true // 默认是false
动态mapjoin使用(/+ streamtable(table_name)/)
连接查询表的大小从左到右依次增长 默认是trueSET hive.auto.convert.join=true // 默认是trueSET hive.mapjoin.smalltable.filesize=600000000 // 默认是25000000,mapjoin的阀值,如果小表小于该值,则会将普通join[reduce join]转为mapjoin
可以参考
启用严格模式:
hive.mapred.mode = strict // Deprecatedhive.strict.checks.large.query = true
该设置会禁用:1. 不指定分页的orderby
2. 对分区表不指定分区进行查询 3. 和数据量无关,只是一个查询模式hive.strict.checks.type.safety = true
严格类型安全,该属性不允许以下操作:1. bigint和string之间的比较
2. bigint和double之间的比较hive.strict.checks.cartesian.product = true
该属性不允许笛卡尔积操作
13. 调整Mapper和Reducer的个数hive.exec.reducers.bytes.per.reducer = 256000000 // 每个reduce任务的字节数,256Mhive.exec.reducers.max = 1009 // reduce task的最大值,属性为负数时,会使用该属性
让多个map/reduce多个实例并发执行
mapreduce.map.speculative = true // 默认是truemapreduce.reduce.speculative = true // 默认是true
hive.multigroupby.singlereducer = true // 默认是true若多个groupby使用的是一个公用的字段,则这些groupby可以生成一个MR
hive.exec.rowoffset = true // 默认是false
转载地址:http://bdwmi.baihongyu.com/