zoukankan      html  css  js  c++  java
  • 加快 hive 查询的 5 种方法

    1. 使用 Tez

    set hive.execution.engine=tez;

    2. 使用 ORCFILE。当有多个表 join 时,使用 ORCFile 进行存储,会显著地提高速度。

    CREATE TABLE A_ORC (
    customerID int, name string, age int, address string
    ) STORED AS ORC tblproperties ("orc.compress" = "SNAPPY");

    3. 使用 VECTORIZATION。会提高 scans, aggregations, filters and joins 等操作的性能。它会把 1024条记录做为一批进行处理,而不是每条记录进行处理。

    set hive.vectorized.execution.enabled = true;
    set hive.vectorized.execution.reduce.enabled = true;

    4. 使用 Cost-based optimization (CBO) 。根据查询代价进行优化。

    set hive.cbo.enable=true;
    set hive.compute.query.using.stats=true;
    set hive.stats.fetch.column.stats=true;
    set hive.stats.fetch.partition.stats=true;

    需要运行 "analyze" 命令为 CBO 收集表的各种统计信息。

    analyze table tbl_student compute statistics;
    analyze table tbl_student compute statistics for columns birthday, race;

    5. 优化 sql

    SELECT clicks.* FROM clicks inner join
    (select sessionID, max(timestamp) as max_ts from clicks
    group by sessionID) latest
    ON clicks.sessionID = latest.sessionID and
    clicks.timestamp = latest.max_ts;

     使用下面的 sql 代替上面的

    SELECT * FROM
    (SELECT *, RANK() over (partition by sessionID,
    order by timestamp desc) as rank
    FROM clicks) ranked_clicks
    WHERE ranked_clicks.rank=1;
  • 相关阅读:
    python 表达式
    anaconda jupyter notebook 启动方法
    python3基本数据类型补充
    Python3 基本数据类型
    pycharm 与 anaconda 关联
    31.Android之常用单位px、dip、sp学习
    30.Android之百度地图简单学习
    29.Android之文本框输入自动提示学习
    28.Android之权限请求汇总
    27.Android之ImageView获取图片学习
  • 原文地址:https://www.cnblogs.com/langfanyun/p/10430352.html
Copyright © 2011-2022 走看看