【问题标题】:Slow performance on Impala query using Group By and Like使用 Group By 和 Like 的 Impala 查询性能缓慢
【发布时间】:2017-06-29 10:13:24
【问题描述】:

我们正在测试 Apache Impala,并注意到将 GROUP BY 和 LIKE 一起使用的速度非常慢 - 单独的查询工作得更快。这里有两个例子:

# 1.37s 1.08s 1.35s

SELECT * FROM hive.default.pcopy1B where 
     (lower("by")  like '%part%' and lower("by")  like '%and%' and lower("by")  like '%the%') 
  or (lower(title) like '%part%' and lower(title) like '%and%' and lower(title) like '%the%') 
  or (lower(url)   like '%part%' and lower(url)   like '%and%' and lower(url)   like '%the%') 
  or (lower(text)  like '%part%' and lower(text)  like '%and%' and lower(text)  like '%the%') 
limit 100;

# 156.64s 155.63s

select "by", type, ranking, count(*) from pcopy where 
     (lower("by")  like '%part%' and lower("by")  like '%and%' and lower("by")  like '%the%') 
  or (lower(title) like '%part%' and lower(title) like '%and%' and lower(title) like '%the%') 
  or (lower(url)   like '%part%' and lower(url)   like '%and%' and lower(url)   like '%the%') 
  or (lower(text)  like '%part%' and lower(text)  like '%and%' and lower(text)  like '%the%') 
group by "by", type, ranking 
order by 4 desc limit 10;

为什么会出现此问题,是否有任何解决方法?

【问题讨论】:

  • 这两个查询对我来说似乎非常不同。第一个只选择记录并且只需要一个游标,第二个必须检索所有记录并运行 GROUP 和 SORT。如果返回的记录非常多,这可能解释了时间差异。还是我错过了什么?

标签: performance hadoop cloudera impala


【解决方案1】:

两个查询之间有一个基本的区别。

第一次查询

要点:

  • 只选择了 100 行。
  • 一旦进程获得满足 WHERE 子句的 100 行,它就会被标记为已完成,并将返回 100 条记录。
  • 只有 1 个映射器步骤。映射器的数量将取决于您的数据大小。

第二次查询

要点:

  • 只选择了 10 行。
  • 即使只选择了 10 行,该过程也需要扫描完整的数据才能根据GROUP BY 子句生成结果。
  • 应该有 3 个 mapper-reducer 步骤。每个步骤的 mapper-reducer 数量将取决于数据大小。
    • 1st MP 将读取数据并应用WHERE 子句
    • 第二个 MR 将用于 GROUP BY 子句。
    • 第三个 MR 将用于 ORDER BY 子句。

因此,您提供的查询可能看起来相似,但它们完全不同,并且共同解决了不同的目的。

【讨论】:

    猜你喜欢
    • 2019-08-21
    • 1970-01-01
    • 2014-06-21
    • 2021-11-17
    • 2013-05-30
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    相关资源
    最近更新 更多