Hive Sort Merge Bucket Map Join


テスト:4000万と5000万以上のテーブルJoin,関連キーデータが傾き,デカルト積,効果が顕著であった.
#テーブルの作成
create table lxw_test1(id int,name string,date_time string)
clustered by(id) sorted by(id) into 10 buckets;

#大きなテーブルの作成
create table lxw_test2(id int,name string,date_time string)
clustered by(id) sorted by(id) into 5 buckets;

注意:2つのテーブルの関連キーはidで、idを押してバケツを分けてソートする必要があります.小さなテーブルのバケツ数は大きなテーブルのバケツ数の倍数です.
#バケツテーブルの有効化
set hive.enforce.bucketing = true;

#小表に4000万件の記録を挿入
insert overwrite table lxw_test1
  select id,name,null  
  from woa_all_user_info_his 
  where pt = '2012-05-28'
  limit 40000000;

#大表に5000万件以上の記録を挿入(woa_all_user_info_hisに5000万件以上の記録がある)
insert overwrite table lxw_test2
 select id,name,date_time
 from woa_all_user_info_his
 where pt = '2012-05-28';

#Sort Merge Bucket Map Joinのパラメータの設定
set hive.optimize.bucketmapjoin = true;
set hive.optimize.bucketmapjoin.sortedmerge = true;
set hive.input.format=org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat;

注意:この場合の状況はBucket columns=Join Columns=Sort Columnsであり、Sort Merge Bucket Map Joinを使用する条件を完全に備えている.
#クエリー
select /*+ mapjoin(b) */ count(1)
from lxw_test1 a 
join lxw_test2 b
on a.id = b.id 

テスト結果:
Insertデータを含め、Sort Merge Bucket Map Join方式で10分程度かかります.
もしこの2つの時計が普通のjoinをしていたら、1時間以上かかり、まだ走りきれず、結局Killを落とすしかなかった!