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;

  • 相关阅读:
    Palindrome Partitioning
    triangle
    Populating Next Right Pointers in Each Node(I and II)
    分苹果(网易)
    Flatten Binary Tree to Linked List
    Construct Binary Tree from Inorder and Postorder Traversal(根据中序遍历和后序遍历构建二叉树)
    iOS系统navigationBar背景色,文字颜色处理
    登录,注销
    ios 文字上下滚动效果Demo
    经常崩溃就是数组字典引起的
  • 原文地址:https://www.cnblogs.com/swordspoet/p/14742332.html
Copyright © 2011-2022 走看看