[英]Hive partition query is scanning all partitions
當我編寫如下所示的 hive 查詢時
select count(*)
from order
where order_month >= '2016-11';
Stage-1 的 Hadoop 作業信息:映射器數量:5; 減速機數量:1
我只有 5 個映射器,這意味着僅讀取所需的分區(2016-11 和 2016-12)
我使用函數編寫的相同查詢
select count(*)
from order
where order_month >= concat(year(DATE_SUB(to_date(from_unixtime(UNIX_TIMESTAMP())),10)),'-',month(DATE_SUB(to_date(from_unixtime(UNIX_TIMESTAMP())),10)));
筆記:
concat(year(DATE_SUB(to_date(from_unixtime(UNIX_TIMESTAMP())),10)),'-',month(DATE_SUB(to_date(from_unixtime(UNIX_TIMESTAMP())),10))) = '2016-11'
Stage-1 的 Hadoop 作業信息:映射器數量:216; 減速機數量:1
這次它正在讀取所有分區{即 2004-10 到 2016-12}。 .
如何修改查詢以僅讀取所需的分區。
unix_timestamp()
函數是不確定的,並且會阻止查詢的正確優化 - 自 2.0 以來已被棄用,以支持CURRENT_TIMESTAMP
和CURRENT_DATE
。
使用current_date,也不需要分別計算年和月:
where order_month >= substr(date_sub(current_date, 10),1,7)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.