高基数字段的Hive查询性能

时间:2018-01-17 07:24:14

标签: hadoop hive

我在hive中有一个但是很大的表,几乎总是用主键列查询(例如,employee_id)。该表将非常庞大,每天插入数百万行,我想使用此字段上的分区快速查询。 I followed this post我知道分区只适用于低基数字段,那么如何才能实现快速查询employee_id列的目标?

我知道具有非常高基数的id列应该用作分组,但它对单表的查询性能没有帮助,是吗?

我认为如果我可以使用像hash(employee_id)之类的东西作为分区,那对我非常有帮助。这可能吗?我无法在关于蜂巢的文件中看到这样的事情。

总结一下,我想要的是快速查询结果:

select * from employee where employee_id=XXX

假设employee表有数十亿条记录,主键列employee_id按年,月,日等进行经典分区无效。

提前致谢,

2 个答案:

答案 0 :(得分:1)

1)将ORC与bloom过滤器一起使用:

CREATE TABLE employee (
  employee_id bigint,
  name STRING
) STORED AS ORC 
TBLPROPERTIES ("orc.bloom.filter.columns"="employee_id")
;

2)使用矢量化启用PPD,使用CBO和Tez:

SET hive.optimize.ppd=true;
SET hive.optimize.ppd.storage=true;
SET hive.vectorized.execution.enabled=true;
SET hive.vectorized.execution.reduce.enabled = true;
SET hive.cbo.enable=true;
set hive.stats.autogather=true;
set hive.compute.query.using.stats=true;
set hive.stats.fetch.partition.stats=true;
set hive.execution.engine=tez;
SET hive.stats.fetch.column.stats=true;
SET hive.tez.auto.reducer.parallelism=true; 

3)在映射器和缩减器上调整适当的并行性:

--example for mappers:

    set tez.grouping.max-size=67108864;
    set tez.grouping.min-size=32000000;


--example settings for reducers: 

    set hive.exec.reducers.bytes.per.reducer=67108864; --decrease this to increase the number of reducers

更改这些数字以达到最佳效果。

答案 1 :(得分:1)

您可以尝试对 hive 表进行存储。存储桶基于高基数字段。这就是哈希的概念。