Hive union all 与 multi insert

Hive union all 与 multi insert执行测试

 

A  insert overwrite table temp_test  select accountbin,accounttype from s_tbl_cardbininfo where accounttype = 'C' union all select accountbin,accounttype from s_tbl_cardbininfo where accounttype = 'D';

 

执行计划:

 

B from s_tbl_cardbininfo  insert overwrite table test_lxw partition (flag = 'C')   select accountbin,accounttype  where accounttype = 'C' insert overwrite table test_lxw partition (flag = 'D')   select accountbin,accounttype  where accounttype = 'D'

 

执行计划:

 

Hive union all 和 multi insert 对于同表都会只加载一次,hive对union all做了很多优化性能要优于multi insert,multi insert用到分区操作复杂了些。测试结果也是union all 要优于multi insert。

 

 

C  insert overwrite table temp_test  select 'countaccountbin', accounttype from s_tbl_cardbininfo where accounttype = 'C' group by accounttype  union all select 'countaccountbin',accounttype from s_tbl_cardbininfo where accounttype = 'D' group by accounttype;

执行计划:

 

D explain from s_tbl_cardbininfo  insert overwrite table test_lxw partition (flag = 'C')   select 'accountbin',accounttype  where accounttype = 'C' group by accounttype insert overwrite table test_lxw partition (flag = 'D')   select 'accountbin',accounttype  where accounttype = 'D' group by accounttype

执行计划:

Hive count,distinct,group by会导致union all 同表关联扫描多次表,multi insert 不会,可以通过调整count,distinct,group by 位置,先执行union all后进行count,distinct,group by来避免这种情况发生。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值