zoukankan      html  css  js  c++  java
  • Hive调优的技巧

    SQL优化

    1. where条件优化

    优化前(关系数据库不用考虑会自动优化):
    select m.cid,u.id from order m join customer u on m.cid =u.id where m.dt='2013-12-12';

    优化后(where条件在map端执行而不是在reduce端执行):
    select m.cid,u.id from (select * from order where dt='2013-12-12') m join customer u on m.cid =u.id;

    1. count distinct优化

    优化前(只有一个reduce,先去重再count负担比较大):
    select count(distinct id) from tablename;
    优化后(启动两个job,一个job负责子查询(可以有多个reduce),另一个job负责count(1)):

    select count(1) from (select distinct id from tablename) tmp;
    
    select count(1) from (select id from tablename group by id) tmp;
    
    1. 数据倾斜

    groupby数据倾斜优化:SET hive.groupby.skewindata=true;
    join过程出现倾斜:SET hive.optimize.skewjoin=true;

    分区

    往hive分区表中插入数据时,如果需要创建的分区很多,比如以表中某个字段进行分区存储,则需要复制粘贴修改很多sql去执行,效率低。因为hive是批处理系统,所以hive提供了一个动态分区功能,其可以基于查询参数的位置去推断分区的名称,从而建立分区。

    hive.exec.dynamic.partition,默认值:false

    是否开启动态分区功能,默认false关闭。使用动态分区时候,该参数必须设置成true;

    hive.exec.dynamic.partition.mode,默认值:strict

    动态分区的模式,默认strict,表示必须指定至少一个分区为静态分区,nonstrict模式表示允许所有的分区字段都可以使用动态分区。一般需要设置为nonstrict

    job

    并行化执行:set hive.exec.parallel=true;

    队列

    设置job的优先级
    set mapred.job.priority=HIGH;

  • 相关阅读:
    no,no,不要使用kill -9
    Linux中etc目录详解
    Quartz任务调度器的使用
    RMI(Remote Method invocation,远程方法访问)
    SilverLight扩展控件RadTreeView
    SiverLight和HTML交互
    SilverLight控件之ContextMenu和RadContextMenu(菜单)
    SilverLight之向后台请求数据-WebClient
    SilverLight控件样式及控件模版
    在SilverLight中代码编写可选择树节点
  • 原文地址:https://www.cnblogs.com/swordspoet/p/14742332.html
Copyright © 2011-2022 走看看