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;
  • 相关阅读:
    08-图9 关键活动 (30 分)
    08-图8 How Long Does It Take (25 分)
    08-图7 公路村村通 (30 分)
    07-图6 旅游规划 (25 分)
    07-图5 Saving James Bond
    使用RichTextBox控件保存文件
    在RichTextBox控件中显示RTF格式文件
    在RichTextBox控件中插入图片
    在RichTextBox控件中添加超链接文本
    实现带查询功能的ComboBox控件
  • 原文地址:https://www.cnblogs.com/langfanyun/p/10430352.html
Copyright © 2011-2022 走看看