hive查询操作优化:
join优化:
hive.optimize.skewjoin=true;如果是join过程出现倾斜 应该设置为true
set hive.skewjoin.key=100000;这个是join的键对应的记录条数超过这个值则会进行优化;
mapjoin:在连接时将小表放入内存中
set hive.auto.convert.join=true; 是否自动转换为mapjoin
hive.mapjoin.smalltable.filesize 设置小于多少启动mapjoin,默认是25mb
hive.auto.convert.join.noconditionaltask : 是否将多个mapjoin合并为一个
hive.auto.convert.join.noconditionaltask.size : 多个mapjoin转换为1个时,所有小表的文件大小总和的最大值。
mapjoin的使用场景:1.关联操作中有一张表非常小,
2.不等值的链接操作
group by 优化
hive.groupby.skewindata=true;如果是group by过程出现数据倾斜 应该设置为true
set hive.groupby.mapaggr.checkinterval=100000;--设置group的键对应记录数超过该值会进行优化
count distinct 优化(数据量比较大时可执行以下优化)
优化前
select count(distinct id) from tablename 只会启动一个reduce
优化后
select count(1) from (select distinct id from tablename) tmp; tmp启动多个reduce
或select count(1) from (select id from tablename group by id) tmp;