首页 > 解决方案 > 从子查询/连接的结果中过滤分区时,Hive Query 将进行全表扫描

问题描述

与 Query2 相比,为什么 query1 运行时间更长。

Hive 源表详细信息

Columns - 166
Partitions columns - 2 columns (all are int datatypes)
Number of Partitions - 3211 partitions
Total Records - 19374461064
File Format - ORC

-- 查询1

create table temp1 as 
with temp_table1 as 
(select col1 from temp_table where col1 between <start_date> and <end_date>), -- these query would get me the dates and there are derived dynamically in the script

select f1.* from sourcetable f1 join temp_table1 f2 on f1.col1=f2.col1;

-- 上述查询运行时间较长,其中一个步骤需要 ~1300 个映射器和 ~1000 个减速器。-- 执行时间 - ~120 分钟

-- 查询2

-- 如果在 where 子句中将 temp table1 的结果作为值传递,则查询将在 10 分钟内检索结果。

select f1.* from source_table where f1.col1 in (value1, value2, value3, value3... value30);

标签: hivehiveqlhive-partitions

解决方案


推荐阅读