【问题标题】:Hive, a small query block join big table , why can't using map join?Hive,一个小查询块join大表,为什么不能使用map join?
【发布时间】:2018-02-20 14:33:51
【问题描述】:

我有一个关于 hive mapjoin 的问题,我知道小表何时加入大表,使用 mapjoin 更好,但是当我得到这样的 sql 时

select a.col1,
       a.col2,
       a.col3, 
       /* there has many columns from table a, ignore..*/
       b.col4,
       b.col5,
       b.col6
  from a
 inner join b
    on (a.id = b.id)
 where b.date = '2018-02-10'
   and b.hour = '10';

提示:
表 b 是大表,行数:10000W+
表 a 是大表,行数:10000W+
带有谓词的表 b 仅返回 1000 行, 我认为这个 sql 将使用 mapjoin ,但执行计划是加入 reduce 端...

谁能告诉我为什么??

【问题讨论】:

  • 连接类型(map 或其他)与查询返回的行数完全无关。表 A 中的给定 ID 可以有多行吗?
  • a.id 和 b.id 没有重复行,a:b 为 1:1

标签: join hive hive-configuration mapjoin


【解决方案1】:

我不是 hive 专家,但有时,用作 SQL 客户端的工具(即 MySQL Workbench)在设置中隐含了 1000 的限制。尝试自己指定一个限制,并将其强制设置为高于 1000 的值。

例如,检查这张图片:

这是 MySQL 工作台。除非您自己指定限制,否则限制会自动添加到您的查询中。

【讨论】:

    【解决方案2】:

    尝试将where 子句移动到子查询中:

    select a.col1,
           a.col2,
           a.col3, 
           /* there has many columns from table a, ignore..*/
           b.col4,
           b.col5,
           b.col6
      from a
     inner join (select * from b where b.date = '2018-02-10' and b.hour = '10' )b 
        on a.id = b.id
     ;
    

    此外,中间过滤(临时)表而不是子查询将 100% 工作,但这不是那么有效。

    还要检查这些 Hive 配置参数:

    set hive.auto.convert.join=true; --this enables map-join
    set hive.mapjoin.smalltable.filesize=25000000; --size of table to fit in memory
    

    如果小表不超过hive.mapjoin.smalltable.filesize参数指定的大小,Join将转换为map-join。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      相关资源
      最近更新 更多