我有一个带有2个分区的蜂巢表,第一个分区是城市,第二个分区是村庄,所以每个城市分区都将包含其中所有村庄分区的列表。类似下面的
city1/village1
city1/village2
city1/village3
city2/village5
city2/village6
因此,如果我的选择语句为select * from table where village = 'village5'
在输出结果之前,它将搜索城市1和城市2中的所有分区吗?还是会看到配置单元metastore文件并仅点击village5分区。
答案 0 :(得分:2)
具体取决于您的Hive版本。在我当前的版本(1.1.0)中,Hive可以指向特定分区,而无需扫描顶部分区
这是一个快速演示。
create table mydb.partition_test
(id string)
partitioned by (city string, village string);
INSERT OVERWRITE TABLE mydb.partition_test PARTITION (city,village)
select * from (
select '1', 'city1', 'village1'
union all
select '1', 'city1', 'village2'
union all
select '1', 'city1', 'village3'
union all
select '1', 'city2', 'village5'
union all
select '1', 'city2', 'village6'
) t;
explain select * from mydb.partition_test where village='village5';
STAGE DEPENDENCIES:
Stage-0 is a root stage
STAGE PLANS:
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
TableScan
alias: partition_test
filterExpr: (village = 'village5') (type: boolean)
Statistics: Num rows: 1 Data size: 1 Basic stats: COMPLETE Column stats: PARTIAL
Select Operator
expressions: id (type: string), city (type: string), 'village5' (type: string)
outputColumnNames: _col0, _col1, _col2
Statistics: Num rows: 1 Data size: 1 Basic stats: COMPLETE Column stats: PARTIAL
ListSink
从执行计划中可以看到,无需映射操作就可以估计该特定分区的记录数,并且表扫描指向该特定分区。