Hive View 查询未使用分区
Hive View query is not using partition
我在 tables 之上有配置单元 tables 和视图。当使用分区列的 where 子句对 Table 执行查询时,我从 explain plain 中看到查询正在使用分区列。但是在查看 运行 时的相同查询,从解释计划中显示没有使用分区键。
请推荐
此处为示例代码,视图是在 table 上创建的,所有列均按 where 子句中的国家/地区代码过滤 (Select * from where country_code='XX')
查询用于 table
SELECT a.unique_id,
a.country_code,
a.rpt_prd,
a.abv_cut_off_scor_flag,
a.acct_und_promo_flag,
.
.
b.arrg_cob_dt,
b.arrg_id
from
a
inner join
b
on a.country_code = b.country_code
and a.product_code = b.product_code
and a.rpt_prd =b.rpt_prd
and a.unique_id =b.unique_id
and a.arrg_id = b.arrg_id
WHERE a.country_code='XX'
AND a.product_code = 'YYYYY'
AND a.rpt_prd ='20171231' ;
a
======================================
Partition Key for - a
PARTITIONED BY ( |
| `country_code` string, |
| `product_code` string, |
| `rpt_prd` string, |
| `unique_id` string)
b
=======================================
PARTITIONED BY ( |
| `country_code` string, |
| `product_code` string, |
| `rpt_prd` string, |
| `unique_id` string)
Query using Views:
===================
SELECT a.unique_id,
a.country_code,
a.rpt_prd,
a.abv_cut_off_scor_flag,
a.acct_und_promo_flag,
.
.
b.arrg_cob_dt,
b.arrg_id
from
a
inner join
b
on a.country_code = b.country_code
and a.product_code = b.product_code
and a.rpt_prd =b.rpt_prd
and a.unique_id =b.unique_id
and a.arrg_id = b.arrg_id
WHERE a.country_code='XX'
AND a.product_code = 'YYYYY'
AND a.rpt_prd ='20171231' ;
由于视图使用与实际相同的基础数据 table 它 应该 使用划分。也就是说,other people have had this issue
一种可能的解决方法是通过创建 partitioned view 语法使视图明确知道分区:
ALTER VIEW view_name ADD PARTITION (partition_col = column_name)
我在 tables 之上有配置单元 tables 和视图。当使用分区列的 where 子句对 Table 执行查询时,我从 explain plain 中看到查询正在使用分区列。但是在查看 运行 时的相同查询,从解释计划中显示没有使用分区键。 请推荐
此处为示例代码,视图是在 table 上创建的,所有列均按 where 子句中的国家/地区代码过滤 (Select * from where country_code='XX')
查询用于 table
SELECT a.unique_id,
a.country_code,
a.rpt_prd,
a.abv_cut_off_scor_flag,
a.acct_und_promo_flag,
.
.
b.arrg_cob_dt,
b.arrg_id
from
a
inner join
b
on a.country_code = b.country_code
and a.product_code = b.product_code
and a.rpt_prd =b.rpt_prd
and a.unique_id =b.unique_id
and a.arrg_id = b.arrg_id
WHERE a.country_code='XX'
AND a.product_code = 'YYYYY'
AND a.rpt_prd ='20171231' ;
a
======================================
Partition Key for - a
PARTITIONED BY ( |
| `country_code` string, |
| `product_code` string, |
| `rpt_prd` string, |
| `unique_id` string)
b
=======================================
PARTITIONED BY ( |
| `country_code` string, |
| `product_code` string, |
| `rpt_prd` string, |
| `unique_id` string)
Query using Views:
===================
SELECT a.unique_id,
a.country_code,
a.rpt_prd,
a.abv_cut_off_scor_flag,
a.acct_und_promo_flag,
.
.
b.arrg_cob_dt,
b.arrg_id
from
a
inner join
b
on a.country_code = b.country_code
and a.product_code = b.product_code
and a.rpt_prd =b.rpt_prd
and a.unique_id =b.unique_id
and a.arrg_id = b.arrg_id
WHERE a.country_code='XX'
AND a.product_code = 'YYYYY'
AND a.rpt_prd ='20171231' ;
由于视图使用与实际相同的基础数据 table 它 应该 使用划分。也就是说,other people have had this issue
一种可能的解决方法是通过创建 partitioned view 语法使视图明确知道分区:
ALTER VIEW view_name ADD PARTITION (partition_col = column_name)